< prev index next >

src/java.base/share/classes/sun/invoke/util/BytecodeName.java

Print this page




 447      * Such names are acceptable in class files as class, method, and field names.
 448      * Additionally, they are free of "dangerous" characters, even if those
 449      * characters are legal in some (or all) names in class files.
 450      * @param s the proposed bytecode name
 451      * @return true if the name is non-empty and all of its characters are safe
 452      */
 453     public static boolean isSafeBytecodeName(String s) {
 454         if (s.length() == 0)  return false;
 455         // check occurrences of each DANGEROUS char
 456         for (char xc : DANGEROUS_CHARS_A) {
 457             if (xc == ESCAPE_C)  continue;  // not really that dangerous
 458             if (s.indexOf(xc) >= 0)  return false;
 459         }
 460         return true;
 461     }
 462 
 463     /**
 464      * Report whether a character is safe in a bytecode name.
 465      * This is true of any unicode character except the following
 466      * <em>dangerous characters</em>: {@code ".;:$[]<>/"}.
 467      * @param s the proposed character
 468      * @return true if the character is safe to use in classfiles
 469      */
 470     public static boolean isSafeBytecodeChar(char c) {
 471         return DANGEROUS_CHARS.indexOf(c) < DANGEROUS_CHAR_FIRST_INDEX;
 472     }
 473 
 474     private static boolean looksMangled(String s) {
 475         return s.charAt(0) == ESCAPE_C;
 476     }
 477 
 478     private static String mangle(String s) {
 479         if (s.length() == 0)
 480             return NULL_ESCAPE;
 481 
 482         // build this lazily, when we first need an escape:
 483         StringBuilder sb = null;
 484 
 485         for (int i = 0, slen = s.length(); i < slen; i++) {
 486             char c = s.charAt(i);
 487 




 447      * Such names are acceptable in class files as class, method, and field names.
 448      * Additionally, they are free of "dangerous" characters, even if those
 449      * characters are legal in some (or all) names in class files.
 450      * @param s the proposed bytecode name
 451      * @return true if the name is non-empty and all of its characters are safe
 452      */
 453     public static boolean isSafeBytecodeName(String s) {
 454         if (s.length() == 0)  return false;
 455         // check occurrences of each DANGEROUS char
 456         for (char xc : DANGEROUS_CHARS_A) {
 457             if (xc == ESCAPE_C)  continue;  // not really that dangerous
 458             if (s.indexOf(xc) >= 0)  return false;
 459         }
 460         return true;
 461     }
 462 
 463     /**
 464      * Report whether a character is safe in a bytecode name.
 465      * This is true of any unicode character except the following
 466      * <em>dangerous characters</em>: {@code ".;:$[]<>/"}.
 467      * @param c the proposed character
 468      * @return true if the character is safe to use in classfiles
 469      */
 470     public static boolean isSafeBytecodeChar(char c) {
 471         return DANGEROUS_CHARS.indexOf(c) < DANGEROUS_CHAR_FIRST_INDEX;
 472     }
 473 
 474     private static boolean looksMangled(String s) {
 475         return s.charAt(0) == ESCAPE_C;
 476     }
 477 
 478     private static String mangle(String s) {
 479         if (s.length() == 0)
 480             return NULL_ESCAPE;
 481 
 482         // build this lazily, when we first need an escape:
 483         StringBuilder sb = null;
 484 
 485         for (int i = 0, slen = s.length(); i < slen; i++) {
 486             char c = s.charAt(i);
 487 


< prev index next >