summaryrefslogtreecommitdiffstats
path: root/icu/src/main/native/RegExInterface.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-09-09 18:15:23 -0700
committerElliott Hughes <enh@google.com>2009-09-10 10:28:12 -0700
commit80e88aa4b239511ea5cdedc7183d05bcbaba908e (patch)
treea57d2734424c79302644f4bf0ce3da166ccfeefd /icu/src/main/native/RegExInterface.cpp
parent91e2974c5b1f3b938a4f1f1c57447d01973ad0ba (diff)
downloadlibcore-80e88aa4b239511ea5cdedc7183d05bcbaba908e.zip
libcore-80e88aa4b239511ea5cdedc7183d05bcbaba908e.tar.gz
libcore-80e88aa4b239511ea5cdedc7183d05bcbaba908e.tar.bz2
Use GetStringRegion/GetStringUTFRegion where appropriate.
Note that the changes to DecimalFormatInterface.cpp and RBNFInterface.cpp are just minor tidy-ups, fixing an issue where the early error exit wouldn't call ReleaseStringChars to undo the earlier call to GetStringChars. Also remove a dead function and fix a comment in ExpatParser.cpp. Tested on sapphire-eng. Bug: 1639287
Diffstat (limited to 'icu/src/main/native/RegExInterface.cpp')
-rw-r--r--icu/src/main/native/RegExInterface.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/icu/src/main/native/RegExInterface.cpp b/icu/src/main/native/RegExInterface.cpp
index afa5cc4..0ca3d06 100644
--- a/icu/src/main/native/RegExInterface.cpp
+++ b/icu/src/main/native/RegExInterface.cpp
@@ -32,12 +32,12 @@ static jchar EMPTY_STRING = 0;
* character data it refers to (but does not have a copy of), so we can
* manage memory properly.
*/
-typedef struct RegExDataStruct {
+struct RegExData {
// A pointer to the ICU regular expression
URegularExpression* regex;
// A pointer to (a copy of) the input text that *we* manage
jchar* text;
-} RegExData;
+};
static void throwPatternSyntaxException(JNIEnv* env, UErrorCode status,
jstring pattern, UParseError error)
@@ -63,8 +63,8 @@ static void _close(JNIEnv* env, jclass clazz, RegExData* data)
uregex_close(data->regex);
}
- if (data->text != NULL && data->text != &EMPTY_STRING) {
- free(data->text);
+ if (data->text != &EMPTY_STRING) {
+ delete[] data->text;
}
free(data);
@@ -125,8 +125,8 @@ static void setText(JNIEnv* env, jclass clazz, RegExData* data, jstring text)
return;
}
- if (data->text != NULL && data->text != &EMPTY_STRING) {
- free(data->text);
+ if (data->text != &EMPTY_STRING) {
+ delete[] data->text;
data->text = NULL;
}
@@ -134,11 +134,9 @@ static void setText(JNIEnv* env, jclass clazz, RegExData* data, jstring text)
if (textLen == 0) {
data->text = &EMPTY_STRING;
} else {
- jchar const * textRaw = env->GetStringChars(text, NULL);
- data->text = (jchar*)malloc((textLen + 1) * sizeof(jchar));
- memcpy(data->text, textRaw, textLen * sizeof(jchar));
+ data->text = new jchar[textLen + 1];
+ env->GetStringRegion(text, 0, textLen, data->text);
data->text[textLen] = 0;
- env->ReleaseStringChars(text, textRaw);
}
uregex_setText(data->regex, data->text, textLen, &status);