ICU-7413 switch Java UCaseProps to use StringBuilder not StringBuffer
X-SVN-Rev: 29995
This commit is contained in:
parent
84da6cfda0
commit
742de93fb5
@ -1,7 +1,7 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2004-2010, International Business Machines
|
||||
* Copyright (C) 2004-2011, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
@ -825,7 +825,7 @@ public final class UCaseProps {
|
||||
* @internal
|
||||
*/
|
||||
public final int toFullLower(int c, ContextIterator iter,
|
||||
StringBuffer out,
|
||||
StringBuilder out,
|
||||
ULocale locale, int[] locCache) {
|
||||
int result, props;
|
||||
|
||||
@ -971,7 +971,7 @@ public final class UCaseProps {
|
||||
|
||||
/* internal */
|
||||
private final int toUpperOrTitle(int c, ContextIterator iter,
|
||||
StringBuffer out,
|
||||
StringBuilder out,
|
||||
ULocale locale, int[] locCache,
|
||||
boolean upperNotTitle) {
|
||||
int result;
|
||||
@ -1066,13 +1066,13 @@ public final class UCaseProps {
|
||||
}
|
||||
|
||||
public final int toFullUpper(int c, ContextIterator iter,
|
||||
StringBuffer out,
|
||||
StringBuilder out,
|
||||
ULocale locale, int[] locCache) {
|
||||
return toUpperOrTitle(c, iter, out, locale, locCache, true);
|
||||
}
|
||||
|
||||
public final int toFullTitle(int c, ContextIterator iter,
|
||||
StringBuffer out,
|
||||
StringBuilder out,
|
||||
ULocale locale, int[] locCache) {
|
||||
return toUpperOrTitle(c, iter, out, locale, locCache, false);
|
||||
}
|
||||
@ -1185,7 +1185,7 @@ public final class UCaseProps {
|
||||
* together in a way that they still fold to common result strings.
|
||||
*/
|
||||
|
||||
public final int toFullFolding(int c, StringBuffer out, int options) {
|
||||
public final int toFullFolding(int c, StringBuilder out, int options) {
|
||||
int result;
|
||||
int props;
|
||||
|
||||
@ -1261,15 +1261,15 @@ public final class UCaseProps {
|
||||
|
||||
private static final int[] rootLocCache = { LOC_ROOT };
|
||||
/*
|
||||
* We need a StringBuffer for multi-code point output from the
|
||||
* We need a StringBuilder for multi-code point output from the
|
||||
* full case mapping functions. However, we do not actually use that output,
|
||||
* we just check whether the input character was mapped to anything else.
|
||||
* We use a shared StringBuffer to avoid allocating a new one in each call.
|
||||
* We use a shared StringBuilder to avoid allocating a new one in each call.
|
||||
* We remove its contents each time so that it does not grow large over time.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public static final StringBuffer dummyStringBuffer = new StringBuffer();
|
||||
public static final StringBuilder dummyStringBuilder = new StringBuilder();
|
||||
|
||||
public final boolean hasBinaryProperty(int c, int which) {
|
||||
switch(which) {
|
||||
@ -1298,21 +1298,21 @@ public final class UCaseProps {
|
||||
* start sets for normalization and case mappings.
|
||||
*/
|
||||
case UProperty.CHANGES_WHEN_LOWERCASED:
|
||||
dummyStringBuffer.setLength(0);
|
||||
return toFullLower(c, null, dummyStringBuffer, ULocale.ROOT, rootLocCache)>=0;
|
||||
dummyStringBuilder.setLength(0);
|
||||
return toFullLower(c, null, dummyStringBuilder, ULocale.ROOT, rootLocCache)>=0;
|
||||
case UProperty.CHANGES_WHEN_UPPERCASED:
|
||||
dummyStringBuffer.setLength(0);
|
||||
return toFullUpper(c, null, dummyStringBuffer, ULocale.ROOT, rootLocCache)>=0;
|
||||
dummyStringBuilder.setLength(0);
|
||||
return toFullUpper(c, null, dummyStringBuilder, ULocale.ROOT, rootLocCache)>=0;
|
||||
case UProperty.CHANGES_WHEN_TITLECASED:
|
||||
dummyStringBuffer.setLength(0);
|
||||
return toFullTitle(c, null, dummyStringBuffer, ULocale.ROOT, rootLocCache)>=0;
|
||||
dummyStringBuilder.setLength(0);
|
||||
return toFullTitle(c, null, dummyStringBuilder, ULocale.ROOT, rootLocCache)>=0;
|
||||
/* case UProperty.CHANGES_WHEN_CASEFOLDED: -- in UCharacterProperty.java */
|
||||
case UProperty.CHANGES_WHEN_CASEMAPPED:
|
||||
dummyStringBuffer.setLength(0);
|
||||
dummyStringBuilder.setLength(0);
|
||||
return
|
||||
toFullLower(c, null, dummyStringBuffer, ULocale.ROOT, rootLocCache)>=0 ||
|
||||
toFullUpper(c, null, dummyStringBuffer, ULocale.ROOT, rootLocCache)>=0 ||
|
||||
toFullTitle(c, null, dummyStringBuffer, ULocale.ROOT, rootLocCache)>=0;
|
||||
toFullLower(c, null, dummyStringBuilder, ULocale.ROOT, rootLocCache)>=0 ||
|
||||
toFullUpper(c, null, dummyStringBuilder, ULocale.ROOT, rootLocCache)>=0 ||
|
||||
toFullTitle(c, null, dummyStringBuilder, ULocale.ROOT, rootLocCache)>=0;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -365,8 +365,8 @@ public final class UCharacterProperty
|
||||
if(c>=0) {
|
||||
/* single code point */
|
||||
UCaseProps csp=UCaseProps.INSTANCE;
|
||||
UCaseProps.dummyStringBuffer.setLength(0);
|
||||
return csp.toFullFolding(c, UCaseProps.dummyStringBuffer,
|
||||
UCaseProps.dummyStringBuilder.setLength(0);
|
||||
return csp.toFullFolding(c, UCaseProps.dummyStringBuilder,
|
||||
UCharacter.FOLD_CASE_DEFAULT)>=0;
|
||||
} else {
|
||||
String folded=UCharacter.foldCase(nfd, true);
|
||||
|
@ -4562,7 +4562,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
*/
|
||||
public static String toUpperCase(ULocale locale, String str) {
|
||||
StringContextIterator iter = new StringContextIterator(str);
|
||||
StringBuffer result = new StringBuffer(str.length());
|
||||
StringBuilder result = new StringBuilder(str.length());
|
||||
int[] locCache = new int[1];
|
||||
int c;
|
||||
|
||||
@ -4583,11 +4583,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
continue;
|
||||
/* } else { append single-code point mapping */
|
||||
}
|
||||
if(c<=0xffff) {
|
||||
result.append((char)c);
|
||||
} else {
|
||||
UTF16.append(result, c);
|
||||
}
|
||||
result.appendCodePoint(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
@ -4615,7 +4611,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
*/
|
||||
public static String toLowerCase(ULocale locale, String str) {
|
||||
StringContextIterator iter = new StringContextIterator(str);
|
||||
StringBuffer result = new StringBuffer(str.length());
|
||||
StringBuilder result = new StringBuilder(str.length());
|
||||
int[] locCache = new int[1];
|
||||
int c;
|
||||
|
||||
@ -4636,11 +4632,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
continue;
|
||||
/* } else { append single-code point mapping */
|
||||
}
|
||||
if(c<=0xffff) {
|
||||
result.append((char)c);
|
||||
} else {
|
||||
UTF16.append(result, c);
|
||||
}
|
||||
result.appendCodePoint(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
@ -4720,7 +4712,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
BreakIterator titleIter,
|
||||
int options) {
|
||||
StringContextIterator iter = new StringContextIterator(str);
|
||||
StringBuffer result = new StringBuffer(str.length());
|
||||
StringBuilder result = new StringBuilder(str.length());
|
||||
int[] locCache = new int[1];
|
||||
int c, nc, srcLength = str.length();
|
||||
|
||||
@ -4795,20 +4787,12 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
if(c<0) {
|
||||
/* (not) original code point */
|
||||
c=~c;
|
||||
if(c<=0xffff) {
|
||||
result.append((char)c);
|
||||
} else {
|
||||
UTF16.append(result, c);
|
||||
}
|
||||
result.appendCodePoint(c);
|
||||
} else if(c<=UCaseProps.MAX_STRING_LENGTH) {
|
||||
/* mapping already appended to result */
|
||||
} else {
|
||||
/* append single-code point mapping */
|
||||
if(c<=0xffff) {
|
||||
result.append((char)c);
|
||||
} else {
|
||||
UTF16.append(result, c);
|
||||
}
|
||||
result.appendCodePoint(c);
|
||||
}
|
||||
|
||||
if((options&TITLECASE_NO_LOWERCASE)!=0) {
|
||||
@ -4953,7 +4937,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
* @stable ICU 2.6
|
||||
*/
|
||||
public static final String foldCase(String str, int options) {
|
||||
StringBuffer result = new StringBuffer(str.length());
|
||||
StringBuilder result = new StringBuilder(str.length());
|
||||
int c, i, length;
|
||||
|
||||
length = str.length();
|
||||
@ -4971,11 +4955,7 @@ public final class UCharacter implements ECharacterCategory, ECharacterDirection
|
||||
continue;
|
||||
/* } else { append single-code point mapping */
|
||||
}
|
||||
if(c<=0xffff) {
|
||||
result.append((char)c);
|
||||
} else {
|
||||
UTF16.append(result, c);
|
||||
}
|
||||
result.appendCodePoint(c);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2000-2010, International Business Machines Corporation and *
|
||||
* Copyright (C) 2000-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -1374,7 +1374,7 @@ public final class Normalizer implements Cloneable {
|
||||
Normalizer2 nfkc=NFKCModeImpl.INSTANCE.normalizer2;
|
||||
UCaseProps csp=UCaseProps.INSTANCE;
|
||||
// first: b = NFKC(Fold(a))
|
||||
StringBuffer folded=new StringBuffer();
|
||||
StringBuilder folded=new StringBuilder();
|
||||
int folded1Length=csp.toFullFolding(c, folded, 0);
|
||||
if(folded1Length<0) {
|
||||
Normalizer2Impl nfkcImpl=((Norm2AllModes.Normalizer2WithImpl)nfkc).impl;
|
||||
@ -2025,7 +2025,7 @@ public final class Normalizer implements Cloneable {
|
||||
String decomp1, decomp2;
|
||||
|
||||
/* case folding buffers, only use current-level start/limit */
|
||||
StringBuffer fold1, fold2;
|
||||
StringBuilder fold1, fold2;
|
||||
|
||||
/* track which is the current level per string */
|
||||
int level1, level2;
|
||||
@ -2049,8 +2049,8 @@ public final class Normalizer implements Cloneable {
|
||||
}
|
||||
if((options&COMPARE_IGNORE_CASE)!=0) {
|
||||
csp=UCaseProps.INSTANCE;
|
||||
fold1=new StringBuffer();
|
||||
fold2=new StringBuffer();
|
||||
fold1=new StringBuilder();
|
||||
fold2=new StringBuilder();
|
||||
} else {
|
||||
csp=null;
|
||||
fold1=fold2=null;
|
||||
|
@ -3661,7 +3661,7 @@ public class UnicodeSet extends UnicodeFilter implements Iterable<String>, Compa
|
||||
|
||||
// add the result of a full case mapping to the set
|
||||
// use str as a temporary string to avoid constructing one
|
||||
private static final void addCaseMapping(UnicodeSet set, int result, StringBuffer full) {
|
||||
private static final void addCaseMapping(UnicodeSet set, int result, StringBuilder full) {
|
||||
if(result >= 0) {
|
||||
if(result > UCaseProps.MAX_STRING_LENGTH) {
|
||||
// add a single-code point case mapping
|
||||
@ -3716,7 +3716,7 @@ public class UnicodeSet extends UnicodeFilter implements Iterable<String>, Compa
|
||||
|
||||
int n = getRangeCount();
|
||||
int result;
|
||||
StringBuffer full = new StringBuffer();
|
||||
StringBuilder full = new StringBuilder();
|
||||
int locCache[] = new int[1];
|
||||
|
||||
for (int i=0; i<n; ++i) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2009-2010, Google, International Business Machines Corporation
|
||||
* Copyright (C) 2009-2011, Google, International Business Machines Corporation
|
||||
* and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -37,7 +37,7 @@ class CaseFoldTransliterator extends Transliterator{
|
||||
|
||||
private UCaseProps csp;
|
||||
private ReplaceableContextIterator iter;
|
||||
private StringBuffer result;
|
||||
private StringBuilder result;
|
||||
|
||||
/**
|
||||
* Constructs a transliterator.
|
||||
@ -47,7 +47,7 @@ class CaseFoldTransliterator extends Transliterator{
|
||||
super(_ID, null);
|
||||
csp=UCaseProps.INSTANCE;
|
||||
iter=new ReplaceableContextIterator();
|
||||
result = new StringBuffer();
|
||||
result = new StringBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2010, International Business Machines Corporation and *
|
||||
* Copyright (C) 1996-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -40,7 +40,7 @@ class LowercaseTransliterator extends Transliterator{
|
||||
|
||||
private UCaseProps csp;
|
||||
private ReplaceableContextIterator iter;
|
||||
private StringBuffer result;
|
||||
private StringBuilder result;
|
||||
private int[] locCache;
|
||||
|
||||
/**
|
||||
@ -52,7 +52,7 @@ class LowercaseTransliterator extends Transliterator{
|
||||
locale = loc;
|
||||
csp=UCaseProps.INSTANCE;
|
||||
iter=new ReplaceableContextIterator();
|
||||
result = new StringBuffer();
|
||||
result = new StringBuilder();
|
||||
locCache = new int[1];
|
||||
locCache[0]=0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 1996-2010, International Business Machines Corporation and
|
||||
* Copyright (C) 1996-2011, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
*
|
||||
*/
|
||||
@ -37,7 +37,7 @@ class TitlecaseTransliterator extends Transliterator {
|
||||
|
||||
private UCaseProps csp;
|
||||
private ReplaceableContextIterator iter;
|
||||
private StringBuffer result;
|
||||
private StringBuilder result;
|
||||
private int[] locCache;
|
||||
|
||||
/**
|
||||
@ -50,7 +50,7 @@ class TitlecaseTransliterator extends Transliterator {
|
||||
setMaximumContextLength(2);
|
||||
csp=UCaseProps.INSTANCE;
|
||||
iter=new ReplaceableContextIterator();
|
||||
result = new StringBuffer();
|
||||
result = new StringBuilder();
|
||||
locCache = new int[1];
|
||||
locCache[0]=0;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 1996-2010, International Business Machines Corporation and *
|
||||
* Copyright (C) 1996-2011, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -37,7 +37,7 @@ class UppercaseTransliterator extends Transliterator {
|
||||
|
||||
private UCaseProps csp;
|
||||
private ReplaceableContextIterator iter;
|
||||
private StringBuffer result;
|
||||
private StringBuilder result;
|
||||
private int[] locCache;
|
||||
|
||||
/**
|
||||
@ -48,7 +48,7 @@ class UppercaseTransliterator extends Transliterator {
|
||||
locale = loc;
|
||||
csp=UCaseProps.INSTANCE;
|
||||
iter=new ReplaceableContextIterator();
|
||||
result = new StringBuffer();
|
||||
result = new StringBuilder();
|
||||
locCache = new int[1];
|
||||
locCache[0]=0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user