This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - add platform specific implementation of unaccent
- Loading branch information
Showing
9 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...form/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.mapbox.mapboxsdk.utils; | ||
|
||
import android.support.annotation.Keep; | ||
import android.support.annotation.NonNull; | ||
|
||
import java.text.Normalizer; | ||
|
||
/** | ||
* String utility class used by core from jni. | ||
*/ | ||
@Keep | ||
class StringUtils { | ||
|
||
/** | ||
* Normalises String input and strip diacritics from it. | ||
* | ||
* @return normalised String with stripped diacritics. | ||
*/ | ||
@Keep | ||
@NonNull | ||
static String unaccent(@NonNull String value) { | ||
return Normalizer.normalize(value, Normalizer.Form.NFD) | ||
.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#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 input = jni::Make<jni::String>(*env, str); | ||
jni::String unaccented = android::StringUtils::unaccent(*env, input); | ||
jni::DeleteLocalRef(*env, input); | ||
std::string output = jni::Make<std::string>(*env, unaccented); | ||
jni::DeleteLocalRef(*env, unaccented); | ||
return output; | ||
} | ||
|
||
} // namespace platform | ||
} // namespace mbgl |