aboutsummaryrefslogtreecommitdiffstats
path: root/native/jni/src/utils/jni_data_utils.h
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-05-14 11:07:32 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-14 11:07:32 +0000
commit5c00bde9bc67d757a33cbaeba7158852c08a39fb (patch)
treee816b7274ea99b6cc5e26e31dff5557df2b1b726 /native/jni/src/utils/jni_data_utils.h
parent728141d55a0a785a4ed09586f7e22272cd49fc96 (diff)
parente9121a68a67b8723477668130a16d4c72d98f6fe (diff)
downloadlatinime-5c00bde9bc67d757a33cbaeba7158852c08a39fb.tar.gz
latinime-5c00bde9bc67d757a33cbaeba7158852c08a39fb.tar.xz
latinime-5c00bde9bc67d757a33cbaeba7158852c08a39fb.zip
Merge "Filter out control characters and non-unicode code points."
Diffstat (limited to 'native/jni/src/utils/jni_data_utils.h')
-rw-r--r--native/jni/src/utils/jni_data_utils.h22
1 files changed, 19 insertions, 3 deletions
diff --git a/native/jni/src/utils/jni_data_utils.h b/native/jni/src/utils/jni_data_utils.h
index 0e393e315..01a5685b4 100644
--- a/native/jni/src/utils/jni_data_utils.h
+++ b/native/jni/src/utils/jni_data_utils.h
@@ -23,6 +23,7 @@
#include "jni.h"
#include "suggest/core/policy/dictionary_header_structure_policy.h"
#include "suggest/policyimpl/dictionary/header/header_read_write_utils.h"
+#include "utils/char_utils.h"
namespace latinime {
@@ -69,16 +70,31 @@ class JniDataUtils {
const int maxLength, const int *const codePoints, const int codePointCount,
const bool needsNullTermination) {
const int outputCodePointCount = std::min(maxLength, codePointCount);
- env->SetIntArrayRegion(intArrayToOutputCodePoints, start, outputCodePointCount, codePoints);
+ int outputCodePonts[outputCodePointCount];
+ for (int i = 0; i < outputCodePointCount; ++i) {
+ const int codePoint = codePoints[i];
+ if (!CharUtils::isInUnicodeSpace(codePoint)) {
+ outputCodePonts[i] = CODE_POINT_REPLACEMENT_CHARACTER;
+ } else if (codePoint >= 0x01 && codePoint <= 0x1F) {
+ // Control code.
+ outputCodePonts[i] = CODE_POINT_REPLACEMENT_CHARACTER;
+ } else {
+ outputCodePonts[i] = codePoint;
+ }
+ }
+ env->SetIntArrayRegion(intArrayToOutputCodePoints, start, outputCodePointCount,
+ outputCodePonts);
if (needsNullTermination && outputCodePointCount < maxLength) {
- const int terminal = 0;
env->SetIntArrayRegion(intArrayToOutputCodePoints, start + outputCodePointCount,
- 1 /* len */, &terminal);
+ 1 /* len */, &CODE_POINT_NULL);
}
}
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(JniDataUtils);
+
+ static const int CODE_POINT_REPLACEMENT_CHARACTER;
+ static const int CODE_POINT_NULL;
};
} // namespace latinime
#endif // LATINIME_JNI_DATA_UTILS_H