mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-1423 make escape() handle supplementals
X-SVN-Rev: 6666
This commit is contained in:
parent
9f91b535fc
commit
98fc1b887a
2 changed files with 18 additions and 32 deletions
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $
|
||||
* $Date: 2001/10/22 05:35:12 $
|
||||
* $Revision: 1.9 $
|
||||
* $Date: 2001/11/07 18:48:23 $
|
||||
* $Revision: 1.10 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -612,26 +612,19 @@ public final class Utility {
|
|||
*/
|
||||
public static final String escape(String s) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i=0; i<s.length(); ++i) {
|
||||
char c = s.charAt(i);
|
||||
for (int i=0; i<s.length(); ) {
|
||||
int c = UTF16.charAt(s, i);
|
||||
i += UTF16.getCharCount(c);
|
||||
if (c >= ' ' && c <= 0x007F) {
|
||||
if (c == '\\') {
|
||||
buf.append("\\\\"); // That is, "\\"
|
||||
} else {
|
||||
buf.append(c);
|
||||
buf.append((char)c);
|
||||
}
|
||||
} else {
|
||||
buf.append("\\u");
|
||||
if (c < 0x1000) {
|
||||
buf.append('0');
|
||||
if (c < 0x100) {
|
||||
buf.append('0');
|
||||
if (c < 0x10) {
|
||||
buf.append('0');
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.append(Integer.toHexString(c));
|
||||
boolean four = c <= 0xFFFF;
|
||||
buf.append(four ? "\\u" : "\\U");
|
||||
hex(c, four ? 4 : 8, buf);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/util/Attic/Utility.java,v $
|
||||
* $Date: 2001/10/22 05:35:12 $
|
||||
* $Revision: 1.9 $
|
||||
* $Date: 2001/11/07 18:48:23 $
|
||||
* $Revision: 1.10 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -612,26 +612,19 @@ public final class Utility {
|
|||
*/
|
||||
public static final String escape(String s) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (int i=0; i<s.length(); ++i) {
|
||||
char c = s.charAt(i);
|
||||
for (int i=0; i<s.length(); ) {
|
||||
int c = UTF16.charAt(s, i);
|
||||
i += UTF16.getCharCount(c);
|
||||
if (c >= ' ' && c <= 0x007F) {
|
||||
if (c == '\\') {
|
||||
buf.append("\\\\"); // That is, "\\"
|
||||
} else {
|
||||
buf.append(c);
|
||||
buf.append((char)c);
|
||||
}
|
||||
} else {
|
||||
buf.append("\\u");
|
||||
if (c < 0x1000) {
|
||||
buf.append('0');
|
||||
if (c < 0x100) {
|
||||
buf.append('0');
|
||||
if (c < 0x10) {
|
||||
buf.append('0');
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.append(Integer.toHexString(c));
|
||||
boolean four = c <= 0xFFFF;
|
||||
buf.append(four ? "\\u" : "\\U");
|
||||
hex(c, four ? 4 : 8, buf);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
|
|
Loading…
Add table
Reference in a new issue