summaryrefslogtreecommitdiff
path: root/platform/android/src/unaccent.cpp
blob: ad804b3aae2b80363099b34328e8093abae49fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <unaccent.hpp>
#include <string>
#include <src/java/lang.hpp>
#include "attach_env.hpp"
#include "text/collator_jni.hpp"

namespace mbgl {
namespace platform {

std::string unaccent(const std::string& str) {
    android::UniqueEnv env = android::AttachEnv();
    jni::String normalized = android::Normalizer::normalize(*env,jni::Make<jni::String>(*env, str));
    jni::String unaccented = android::java::lang::String::replaceAll(*env, normalized,
                                                                     jni::Make<jni::String>(*env, "\\p{InCombiningDiacriticalMarks}+"),
                                                                     jni::Make<jni::String>(*env, ""));
    return jni::Make<std::string>(*env, unaccented);
}

} // namespace platform
} // namespace mbgl