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] - replace platform default implementation using nunicode fo…
…r uppercasing an lowercasing with an Android specific String.java equivalent
- Loading branch information
Showing
11 changed files
with
148 additions
and
7 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...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,27 @@ | ||
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}" | ||
+ "|\\p{InCombiningDiacriticalMarksForSymbols}" | ||
+ "|\\p{InCombiningDiacriticalMarksSupplement})+", ""); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...TestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/string/UppperLowerCaseTest.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,50 @@ | ||
package com.mapbox.mapboxsdk.testapp.string; | ||
|
||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; | ||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; | ||
import org.junit.Test; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
|
||
/** | ||
* Test verifying if String#toUpperCase and String#toLowerCase produces desired results | ||
* <p> | ||
* See core test in https://github.com/mapbox/mapbox-gl-native/blob/master/test/util/text_conversions.test.cpp | ||
* </p> | ||
*/ | ||
public class UppperLowerCaseTest extends BaseActivityTest { | ||
|
||
@Override | ||
protected Class getActivityClass() { | ||
return EspressoTestActivity.class; | ||
} | ||
|
||
@Test | ||
public void testToUpperCase() { | ||
assertEquals("STREET", "strEEt".toUpperCase()); // EN | ||
assertEquals("ROAD", "rOAd".toUpperCase()); // EN | ||
|
||
assertEquals("STRASSE", "straße".toUpperCase()); // DE | ||
assertEquals("MASSE", "maße".toUpperCase()); // DE | ||
assertEquals("WEISSKOPFSEEADLER", "weißkopfseeadler".toUpperCase()); // DE | ||
|
||
assertEquals("BÊNÇÃO", "bênção".toUpperCase()); // PT | ||
assertEquals("AZƏRBAYCAN", "Azərbaycan".toUpperCase()); // AZ | ||
assertEquals("ὈΔΥΣΣΕΎΣ", "Ὀδυσσεύς".toUpperCase()); // GR | ||
} | ||
|
||
@Test | ||
public void testToLowerCase() { | ||
assertEquals("street", "strEEt".toLowerCase()); // EN | ||
assertEquals("road", "rOAd".toLowerCase()); // EN | ||
|
||
assertEquals("straße", "Straße".toLowerCase()); // DE | ||
assertEquals("strasse", "STRASSE".toLowerCase()); // DE | ||
assertEquals("masse", "MASSE".toLowerCase()); // DE | ||
assertEquals("weisskopfseeadler", "weiSSkopfseeadler".toLowerCase()); // DE | ||
|
||
assertEquals("bênção", "BÊNÇÃO".toLowerCase()); // PT | ||
assertEquals("azərbaycan", "AZƏRBAYCAN".toLowerCase()); // | ||
} | ||
|
||
} |
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,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 |
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,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 |