libcore_icu_NativeNormalizer.cpp revision 5ec69b20ab9b3e2dcbe225d548168b09afbbbac2
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#define LOG_TAG "NativeNormalizer" 18 19#include "JNIHelp.h" 20#include "JniConstants.h" 21#include "JniException.h" 22#include "ScopedJavaUnicodeString.h" 23#include "unicode/normlzr.h" 24 25static jstring NativeNormalizer_normalizeImpl(JNIEnv* env, jclass, jstring s, jint intMode) { 26 ScopedJavaUnicodeString src(env, s); 27 UNormalizationMode mode = static_cast<UNormalizationMode>(intMode); 28 UErrorCode status = U_ZERO_ERROR; 29 UnicodeString dst; 30 Normalizer::normalize(src.unicodeString(), mode, 0, dst, status); 31 maybeThrowIcuException(env, "Normalizer::normalize", status); 32 return dst.isBogus() ? NULL : env->NewString(dst.getBuffer(), dst.length()); 33} 34 35static jboolean NativeNormalizer_isNormalizedImpl(JNIEnv* env, jclass, jstring s, jint intMode) { 36 ScopedJavaUnicodeString src(env, s); 37 UNormalizationMode mode = static_cast<UNormalizationMode>(intMode); 38 UErrorCode status = U_ZERO_ERROR; 39 UBool result = Normalizer::isNormalized(src.unicodeString(), mode, status); 40 maybeThrowIcuException(env, "Normalizer::isNormalized", status); 41 return result; 42} 43 44static JNINativeMethod gMethods[] = { 45 NATIVE_METHOD(NativeNormalizer, normalizeImpl, "(Ljava/lang/String;I)Ljava/lang/String;"), 46 NATIVE_METHOD(NativeNormalizer, isNormalizedImpl, "(Ljava/lang/String;I)Z"), 47}; 48void register_libcore_icu_NativeNormalizer(JNIEnv* env) { 49 jniRegisterNativeMethods(env, "libcore/icu/NativeNormalizer", gMethods, NELEM(gMethods)); 50} 51