[android] - replace platform default implementation using nunicode for uppercasing an lowercasing with an Android specific String.java equivalent
This commit is contained in:
@@ -187,6 +187,7 @@ void registerNatives(JavaVM *vm) {
|
||||
LocalGlyphRasterizer::registerNative(env);
|
||||
Locale::registerNative(env);
|
||||
Collator::registerNative(env);
|
||||
StringUtils::registerNative(env);
|
||||
|
||||
// Logger
|
||||
Logger::registerNative(env);
|
||||
|
||||
25
platform/android/src/string_util.cpp
Normal file
25
platform/android/src/string_util.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <mbgl/util/platform.hpp>
|
||||
#include "attach_env.hpp"
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
std::string uppercase(const std::string& str) {
|
||||
auto env{ android::AttachEnv() };
|
||||
jni::Local<jni::String> value = jni::Make<jni::String>(*env, str.c_str());
|
||||
static auto toUpperCase = jni::Class<jni::StringTag>::Singleton(*env).GetMethod<jni::String()>(*env, "toUpperCase");
|
||||
auto result = value.Call(*env, toUpperCase);
|
||||
return jni::Make<std::string>(*env, result);
|
||||
}
|
||||
|
||||
std::string lowercase(const std::string& str) {
|
||||
auto env{ android::AttachEnv() };
|
||||
jni::Local<jni::String> value = jni::Make<jni::String>(*env, str.c_str());
|
||||
static auto toLowerCase = jni::Class<jni::StringTag>::Singleton(*env).GetMethod<jni::String()>(*env, "toLowerCase");
|
||||
auto result = value.Call(*env, toLowerCase);
|
||||
return jni::Make<std::string>(*env, result);
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
@@ -30,10 +30,20 @@ void Collator::setStrength(jni::JNIEnv& env, const jni::Object<Collator>& collat
|
||||
|
||||
jni::jint Collator::compare(jni::JNIEnv& env, const jni::Object<Collator>& collator, const jni::String& lhs, const jni::String& rhs) {
|
||||
static auto& javaClass = jni::Class<Collator>::Singleton(env);
|
||||
auto static method = javaClass.GetMethod<jni::jint (jni::String, jni::String)>(env, "compare");
|
||||
static auto method = javaClass.GetMethod<jni::jint (jni::String, jni::String)>(env, "compare");
|
||||
return collator.Call(env, method, lhs, rhs);
|
||||
}
|
||||
|
||||
void StringUtils::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<StringUtils>::Singleton(env);
|
||||
}
|
||||
|
||||
jni::Local<jni::String> StringUtils::unaccent(jni::JNIEnv& env, const jni::String& value) {
|
||||
static auto& javaClass = jni::Class<StringUtils>::Singleton(env);
|
||||
static auto method = javaClass.GetStaticMethod<jni::String (jni::String)>(env, "unaccent");
|
||||
return javaClass.Call(env, method, value);
|
||||
}
|
||||
|
||||
void Locale::registerNative(jni::JNIEnv& env) {
|
||||
jni::Class<Locale>::Singleton(env);
|
||||
}
|
||||
|
||||
@@ -49,5 +49,16 @@ public:
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
|
||||
class StringUtils {
|
||||
public:
|
||||
static constexpr auto Name() { return "com/mapbox/mapboxsdk/utils/StringUtils"; };
|
||||
|
||||
static jni::Local<jni::String> unaccent(jni::JNIEnv&, const jni::String&);
|
||||
|
||||
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
} // namespace mbgl
|
||||
|
||||
18
platform/android/src/unaccent.cpp
Normal file
18
platform/android/src/unaccent.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <unaccent.hpp>
|
||||
#include <string>
|
||||
#include "attach_env.hpp"
|
||||
#include "text/collator_jni.hpp"
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace platform {
|
||||
|
||||
std::string unaccent(const std::string& str) {
|
||||
android::UniqueEnv env = android::AttachEnv();
|
||||
jni::Local<jni::String> input = jni::Make<jni::String>(*env, str);
|
||||
jni::Local<jni::String> unaccented = android::StringUtils::unaccent(*env, input);
|
||||
return jni::Make<std::string>(*env, unaccented);
|
||||
}
|
||||
|
||||
} // namespace platform
|
||||
} // namespace mbgl
|
||||
Reference in New Issue
Block a user