< prev index next >

src/java.base/share/classes/sun/text/normalizer/Utility.java

Print this page




 210             } else if (c < UNESCAPE_MAP[i]) {
 211                 break;
 212             }
 213         }
 214 
 215         /* Map \cX to control-X: X & 0x1F */
 216         if (c == 'c' && offset < length) {
 217             c = UTF16.charAt(s, offset);
 218             offset16[0] = offset + UTF16.getCharCount(c);
 219             return 0x1F & c;
 220         }
 221 
 222         /* If no special forms are recognized, then consider
 223          * the backslash to generically escape the next character. */
 224         offset16[0] = offset;
 225         return c;
 226     }
 227 
 228     /**
 229      * Convert a integer to size width hex uppercase digits.
 230      * E.g., hex('a', 4, str) => "0041".
 231      * Append the output to the given StringBuffer.
 232      * If width is too small to fit, nothing will be appended to output.
 233      */
 234     public static StringBuffer hex(int ch, int width, StringBuffer output) {
 235         return appendNumber(output, ch, 16, width);
 236     }
 237 
 238     /**
 239      * Convert a integer to size width (minimum) hex uppercase digits.
 240      * E.g., hex('a', 4, str) => "0041".  If the integer requires more
 241      * than width digits, more will be used.
 242      */
 243     public static String hex(int ch, int width) {
 244         StringBuffer buf = new StringBuffer();
 245         return appendNumber(buf, ch, 16, width).toString();
 246     }
 247 
 248     /**
 249      * Skip over a sequence of zero or more white space characters
 250      * at pos.  Return the index of the first non-white-space character
 251      * at or after pos, or str.length(), if there is none.
 252      */
 253     public static int skipWhitespace(String str, int pos) {
 254         while (pos < str.length()) {
 255             int c = UTF16.charAt(str, pos);
 256             if (!UCharacterProperty.isRuleWhiteSpace(c)) {
 257                 break;
 258             }
 259             pos += UTF16.getCharCount(c);
 260         }


 317 
 318         if (n < 0) {
 319             abs = -n;
 320             result.append("-");
 321         }
 322 
 323         recursiveAppendNumber(result, abs, radix, minDigits);
 324 
 325         return result;
 326     }
 327 
 328     /**
 329      * Return true if the character is NOT printable ASCII.  The tab,
 330      * newline and linefeed characters are considered unprintable.
 331      */
 332     public static boolean isUnprintable(int c) {
 333         return !(c >= 0x20 && c <= 0x7E);
 334     }
 335 
 336     /**
 337      * Escape unprintable characters using <backslash>uxxxx notation
 338      * for U+0000 to U+FFFF and <backslash>Uxxxxxxxx for U+10000 and
 339      * above.  If the character is printable ASCII, then do nothing
 340      * and return FALSE.  Otherwise, append the escaped notation and
 341      * return TRUE.
 342      */
 343     public static boolean escapeUnprintable(StringBuffer result, int c) {
 344         if (isUnprintable(c)) {
 345             result.append('\\');
 346             if ((c & ~0xFFFF) != 0) {
 347                 result.append('U');
 348                 result.append(DIGITS[0xF&(c>>28)]);
 349                 result.append(DIGITS[0xF&(c>>24)]);
 350                 result.append(DIGITS[0xF&(c>>20)]);
 351                 result.append(DIGITS[0xF&(c>>16)]);
 352             } else {
 353                 result.append('u');
 354             }
 355             result.append(DIGITS[0xF&(c>>12)]);
 356             result.append(DIGITS[0xF&(c>>8)]);
 357             result.append(DIGITS[0xF&(c>>4)]);
 358             result.append(DIGITS[0xF&c]);




 210             } else if (c < UNESCAPE_MAP[i]) {
 211                 break;
 212             }
 213         }
 214 
 215         /* Map \cX to control-X: X & 0x1F */
 216         if (c == 'c' && offset < length) {
 217             c = UTF16.charAt(s, offset);
 218             offset16[0] = offset + UTF16.getCharCount(c);
 219             return 0x1F & c;
 220         }
 221 
 222         /* If no special forms are recognized, then consider
 223          * the backslash to generically escape the next character. */
 224         offset16[0] = offset;
 225         return c;
 226     }
 227 
 228     /**
 229      * Convert a integer to size width hex uppercase digits.
 230      * E.g., {@code hex('a', 4, str) => "0041"}.
 231      * Append the output to the given StringBuffer.
 232      * If width is too small to fit, nothing will be appended to output.
 233      */
 234     public static StringBuffer hex(int ch, int width, StringBuffer output) {
 235         return appendNumber(output, ch, 16, width);
 236     }
 237 
 238     /**
 239      * Convert a integer to size width (minimum) hex uppercase digits.
 240      * E.g., {@code hex('a', 4, str) => "0041"}.  If the integer requires more
 241      * than width digits, more will be used.
 242      */
 243     public static String hex(int ch, int width) {
 244         StringBuffer buf = new StringBuffer();
 245         return appendNumber(buf, ch, 16, width).toString();
 246     }
 247 
 248     /**
 249      * Skip over a sequence of zero or more white space characters
 250      * at pos.  Return the index of the first non-white-space character
 251      * at or after pos, or str.length(), if there is none.
 252      */
 253     public static int skipWhitespace(String str, int pos) {
 254         while (pos < str.length()) {
 255             int c = UTF16.charAt(str, pos);
 256             if (!UCharacterProperty.isRuleWhiteSpace(c)) {
 257                 break;
 258             }
 259             pos += UTF16.getCharCount(c);
 260         }


 317 
 318         if (n < 0) {
 319             abs = -n;
 320             result.append("-");
 321         }
 322 
 323         recursiveAppendNumber(result, abs, radix, minDigits);
 324 
 325         return result;
 326     }
 327 
 328     /**
 329      * Return true if the character is NOT printable ASCII.  The tab,
 330      * newline and linefeed characters are considered unprintable.
 331      */
 332     public static boolean isUnprintable(int c) {
 333         return !(c >= 0x20 && c <= 0x7E);
 334     }
 335 
 336     /**
 337      * Escape unprintable characters using {@code <backslash>uxxxx} notation
 338      * for U+0000 to U+FFFF and {@code <backslash>Uxxxxxxxx} for U+10000 and
 339      * above.  If the character is printable ASCII, then do nothing
 340      * and return FALSE.  Otherwise, append the escaped notation and
 341      * return TRUE.
 342      */
 343     public static boolean escapeUnprintable(StringBuffer result, int c) {
 344         if (isUnprintable(c)) {
 345             result.append('\\');
 346             if ((c & ~0xFFFF) != 0) {
 347                 result.append('U');
 348                 result.append(DIGITS[0xF&(c>>28)]);
 349                 result.append(DIGITS[0xF&(c>>24)]);
 350                 result.append(DIGITS[0xF&(c>>20)]);
 351                 result.append(DIGITS[0xF&(c>>16)]);
 352             } else {
 353                 result.append('u');
 354             }
 355             result.append(DIGITS[0xF&(c>>12)]);
 356             result.append(DIGITS[0xF&(c>>8)]);
 357             result.append(DIGITS[0xF&(c>>4)]);
 358             result.append(DIGITS[0xF&c]);


< prev index next >