java.lang.Character Java Examples

The following examples show how to use java.lang.Character. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ORBUtility.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
Example #2
Source File: URI.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #3
Source File: URI.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #4
Source File: URI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #5
Source File: ORBUtility.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
Example #6
Source File: URI.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #7
Source File: ORBUtility.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
Example #8
Source File: ORBUtility.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
Example #9
Source File: ORBUtility.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
Example #10
Source File: URI.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #11
Source File: URI.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #12
Source File: ORBUtility.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
Example #13
Source File: URI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #14
Source File: URI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #15
Source File: ORBUtility.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static boolean isPrintable(char c)
{
    if (Character.isJavaIdentifierStart(c)) {
        // Letters and $ _
        return true;
    }
    if (Character.isDigit(c)) {
        return true;
    }
    switch (Character.getType(c)) {
    case Character.MODIFIER_SYMBOL : return true; // ` ^
    case Character.DASH_PUNCTUATION : return true; // -
    case Character.MATH_SYMBOL : return true; // = ~ + | < >
    case Character.OTHER_PUNCTUATION : return true; // !@#%&*;':",./?
    case Character.START_PUNCTUATION : return true; // ( [ {
    case Character.END_PUNCTUATION : return true; // ) ] }
    }
    return false;
}
 
Example #16
Source File: URI.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private int scanEscape(int start, int n, char first)
    throws URISyntaxException
{
    int p = start;
    char c = first;
    if (c == '%') {
        // Process escape pair
        if ((p + 3 <= n)
            && match(charAt(p + 1), L_HEX, H_HEX)
            && match(charAt(p + 2), L_HEX, H_HEX)) {
            return p + 3;
        }
        fail("Malformed escape pair", p);
    } else if ((c > 128)
               && !Character.isSpaceChar(c)
               && !Character.isISOControl(c)) {
        // Allow unescaped but visible non-US-ASCII chars
        return p + 1;
    }
    return p;
}
 
Example #17
Source File: GeneratedDatabaseHolder.java    From WeatherStream with Apache License 2.0 5 votes vote down vote up
public GeneratedDatabaseHolder() {
  typeConverters.put(Boolean.class, new BooleanConverter());
  typeConverters.put(Character.class, new CharConverter());
  typeConverters.put(BigDecimal.class, new BigDecimalConverter());
  typeConverters.put(BigInteger.class, new BigIntegerConverter());
  typeConverters.put(Date.class, new SqlDateConverter());
  typeConverters.put(Time.class, new SqlDateConverter());
  typeConverters.put(Timestamp.class, new SqlDateConverter());
  typeConverters.put(Calendar.class, new CalendarConverter());
  typeConverters.put(GregorianCalendar.class, new CalendarConverter());
  typeConverters.put(java.util.Date.class, new DateConverter());
  typeConverters.put(UUID.class, new UUIDConverter());
  new WeatherStreamDBWeatherStreamDB_Database(this);
}
 
Example #18
Source File: PatternEntry.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #19
Source File: PatternEntry.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #20
Source File: URI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static String quote(String s, long lowMask, long highMask) {
    int n = s.length();
    StringBuffer sb = null;
    boolean allowNonASCII = ((lowMask & L_ESCAPED) != 0);
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c < '\u0080') {
            if (!match(c, lowMask, highMask)) {
                if (sb == null) {
                    sb = new StringBuffer();
                    sb.append(s.substring(0, i));
                }
                appendEscape(sb, (byte)c);
            } else {
                if (sb != null)
                    sb.append(c);
            }
        } else if (allowNonASCII
                   && (Character.isSpaceChar(c)
                       || Character.isISOControl(c))) {
            if (sb == null) {
                sb = new StringBuffer();
                sb.append(s.substring(0, i));
            }
            appendEncoded(sb, c);
        } else {
            if (sb != null)
                sb.append(c);
        }
    }
    return (sb == null) ? s : sb.toString();
}
 
Example #21
Source File: URI.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String quote(String s, long lowMask, long highMask) {
    int n = s.length();
    StringBuffer sb = null;
    boolean allowNonASCII = ((lowMask & L_ESCAPED) != 0);
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c < '\u0080') {
            if (!match(c, lowMask, highMask)) {
                if (sb == null) {
                    sb = new StringBuffer();
                    sb.append(s.substring(0, i));
                }
                appendEscape(sb, (byte)c);
            } else {
                if (sb != null)
                    sb.append(c);
            }
        } else if (allowNonASCII
                   && (Character.isSpaceChar(c)
                       || Character.isISOControl(c))) {
            if (sb == null) {
                sb = new StringBuffer();
                sb.append(s.substring(0, i));
            }
            appendEncoded(sb, c);
        } else {
            if (sb != null)
                sb.append(c);
        }
    }
    return (sb == null) ? s : sb.toString();
}
 
Example #22
Source File: URI.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private static String quote(String s, long lowMask, long highMask) {
    int n = s.length();
    StringBuffer sb = null;
    boolean allowNonASCII = ((lowMask & L_ESCAPED) != 0);
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c < '\u0080') {
            if (!match(c, lowMask, highMask)) {
                if (sb == null) {
                    sb = new StringBuffer();
                    sb.append(s.substring(0, i));
                }
                appendEscape(sb, (byte)c);
            } else {
                if (sb != null)
                    sb.append(c);
            }
        } else if (allowNonASCII
                   && (Character.isSpaceChar(c)
                       || Character.isISOControl(c))) {
            if (sb == null) {
                sb = new StringBuffer();
                sb.append(s.substring(0, i));
            }
            appendEncoded(sb, c);
        } else {
            if (sb != null)
                sb.append(c);
        }
    }
    return (sb == null) ? s : sb.toString();
}
 
Example #23
Source File: URI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static String quote(String s, long lowMask, long highMask) {
    StringBuilder sb = null;
    boolean allowNonASCII = ((lowMask & L_ESCAPED) != 0);
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c < '\u0080') {
            if (!match(c, lowMask, highMask)) {
                if (sb == null) {
                    sb = new StringBuilder();
                    sb.append(s, 0, i);
                }
                appendEscape(sb, (byte)c);
            } else {
                if (sb != null)
                    sb.append(c);
            }
        } else if (allowNonASCII
                   && (Character.isSpaceChar(c)
                       || Character.isISOControl(c))) {
            if (sb == null) {
                sb = new StringBuilder();
                sb.append(s, 0, i);
            }
            appendEncoded(sb, c);
        } else {
            if (sb != null)
                sb.append(c);
        }
    }
    return (sb == null) ? s : sb.toString();
}
 
Example #24
Source File: PatternEntry.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #25
Source File: PatternEntry.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #26
Source File: PatternEntry.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #27
Source File: PatternEntry.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #28
Source File: PatternEntry.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #29
Source File: PatternEntry.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void appendQuoted(String chars, StringBuffer toAddTo) {
    boolean inQuote = false;
    char ch = chars.charAt(0);
    if (Character.isSpaceChar(ch)) {
        inQuote = true;
        toAddTo.append('\'');
    } else {
      if (PatternEntry.isSpecialChar(ch)) {
            inQuote = true;
            toAddTo.append('\'');
        } else {
            switch (ch) {
                case 0x0010: case '\f': case '\r':
                case '\t': case '\n':  case '@':
                inQuote = true;
                toAddTo.append('\'');
                break;
            case '\'':
                inQuote = true;
                toAddTo.append('\'');
                break;
            default:
                if (inQuote) {
                    inQuote = false; toAddTo.append('\'');
                }
                break;
            }
       }
    }
    toAddTo.append(chars);
    if (inQuote)
        toAddTo.append('\'');
}
 
Example #30
Source File: URI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static String quote(String s, long lowMask, long highMask) {
    int n = s.length();
    StringBuffer sb = null;
    boolean allowNonASCII = ((lowMask & L_ESCAPED) != 0);
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (c < '\u0080') {
            if (!match(c, lowMask, highMask)) {
                if (sb == null) {
                    sb = new StringBuffer();
                    sb.append(s.substring(0, i));
                }
                appendEscape(sb, (byte)c);
            } else {
                if (sb != null)
                    sb.append(c);
            }
        } else if (allowNonASCII
                   && (Character.isSpaceChar(c)
                       || Character.isISOControl(c))) {
            if (sb == null) {
                sb = new StringBuffer();
                sb.append(s.substring(0, i));
            }
            appendEncoded(sb, c);
        } else {
            if (sb != null)
                sb.append(c);
        }
    }
    return (sb == null) ? s : sb.toString();
}