ANDROID社区
  • 源代码
  • 资讯
  • 技术文章
  • 代码片断
  • 工具
      
    • 我收藏的代码
    • 我读过的代码
    • 我收藏的文章
    • 退出登录
    注册 | 登录
Marshmallow  |  6.0.1_r16

下载     查看原文件     收藏
  1. 根目录:
  2. libnativehelper
  3. toStringArray.cpp
C++程序  |  49行  |  1.43 KB
  • 原始内容
  • 高亮显示
  • 复制内容
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "JniConstants.h"
#include "toStringArray.h"

jobjectArray newStringArray(JNIEnv* env, size_t count) {
    return env->NewObjectArray(count, JniConstants::stringClass, NULL);
}

struct ArrayCounter {
    const char* const* strings;
    ArrayCounter(const char* const* strings) : strings(strings) {}
    size_t operator()() {
        size_t count = 0;
        while (strings[count] != NULL) {
            ++count;
        }
        return count;
    }
};

struct ArrayGetter {
    const char* const* strings;
    ArrayGetter(const char* const* strings) : strings(strings) {}
    const char* operator()(size_t i) {
        return strings[i];
    }
};

jobjectArray toStringArray(JNIEnv* env, const char* const* strings) {
    ArrayCounter counter(strings);
    ArrayGetter getter(strings);
    return toStringArray(env, &counter, &getter);
}

已收藏

收藏成功,您可以在我收藏的代码页面中查看,其地址为:https://www.androidos.net.cn/my/collect/code。

网站相关

  • 关于我们 - 理想与情怀,使命与责任
  • 反馈建议或意见

常用链接

  • 土拨鼠 - 互联网工具小站
  • Android社区 - 汇集优秀技术文章
  • Flutter - 快速构建你的iOS && Android应用

关于

提供Android系统源代码在线阅读功能,同时我们采集了一些优秀的解读系统的文章并得到作者的援权发布。希望本站能成为您学习Android系统,进行Android开发的良师益友。

Copyright© 2013-2016 All Rights Reserved 京ICP备18004812号-1    京公网安备 11010502044971号