mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-75 add unescapeLeniently()
X-SVN-Rev: 6284
This commit is contained in:
parent
b8821ea393
commit
edb9849ffd
2 changed files with 54 additions and 4 deletions
icu4j/src/com/ibm
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Utility.java,v $
|
||||
* $Date: 2001/09/24 19:57:51 $
|
||||
* $Revision: 1.7 $
|
||||
* $Date: 2001/10/17 20:09:44 $
|
||||
* $Revision: 1.8 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -771,6 +771,31 @@ public final class Utility {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all escapes in a given string using unescapeAt().
|
||||
* Leave invalid escape sequences unchanged.
|
||||
*/
|
||||
public static String unescapeLeniently(String s) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int[] pos = new int[1];
|
||||
for (int i=0; i<s.length(); ) {
|
||||
char c = s.charAt(i++);
|
||||
if (c == '\\') {
|
||||
pos[0] = i;
|
||||
int e = unescapeAt(s, pos);
|
||||
if (e < 0) {
|
||||
buf.append(c);
|
||||
} else {
|
||||
UTF16.append(buf, e);
|
||||
i = pos[0];
|
||||
}
|
||||
} else {
|
||||
buf.append(c);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a char to 4 hex uppercase digits. E.g., hex('a') =>
|
||||
* "0041".
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/util/Attic/Utility.java,v $
|
||||
* $Date: 2001/09/24 19:57:51 $
|
||||
* $Revision: 1.7 $
|
||||
* $Date: 2001/10/17 20:09:44 $
|
||||
* $Revision: 1.8 $
|
||||
*
|
||||
*****************************************************************************************
|
||||
*/
|
||||
|
@ -771,6 +771,31 @@ public final class Utility {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert all escapes in a given string using unescapeAt().
|
||||
* Leave invalid escape sequences unchanged.
|
||||
*/
|
||||
public static String unescapeLeniently(String s) {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
int[] pos = new int[1];
|
||||
for (int i=0; i<s.length(); ) {
|
||||
char c = s.charAt(i++);
|
||||
if (c == '\\') {
|
||||
pos[0] = i;
|
||||
int e = unescapeAt(s, pos);
|
||||
if (e < 0) {
|
||||
buf.append(c);
|
||||
} else {
|
||||
UTF16.append(buf, e);
|
||||
i = pos[0];
|
||||
}
|
||||
} else {
|
||||
buf.append(c);
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a char to 4 hex uppercase digits. E.g., hex('a') =>
|
||||
* "0041".
|
||||
|
|
Loading…
Add table
Reference in a new issue