private static String escape_PN_LOCAL_ESC(String x) { // Assume that escapes are rare so scan once to make sure there // is work to do then scan again doing the work. //'\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%') int N = x.length() ; boolean escchar = false ; for ( int i = 0 ; i < N ; i++ ) { char ch = x.charAt(i) ; if ( needsEscape(ch, (i==N-1)) ) { escchar = true ; break ; } } if ( ! escchar ) return x ; StringBuilder sb = new StringBuilder(N+10) ; for ( int i = 0 ; i < N ; i++ ) { char ch = x.charAt(i) ; // DOT only needs escaping at the end if ( needsEscape(ch, (i==N-1) ) ) sb.append('\\') ; sb.append(ch) ; } return sb.toString() ; }
private static String escape_PN_LOCAL_ESC(String x) { // Assume that escapes are rare so scan once to make sure there // is work to do then scan again doing the work. //'\' ('_' | '~' | '.' | '-' | '!' | '$' | '&' | "'" | '(' | ')' | '*' | '+' | ',' | ';' | '=' | '/' | '?' | '#' | '@' | '%') int N = x.length() ; boolean escchar = false ; for ( int i = 0 ; i < N ; i++ ) { char ch = x.charAt(i) ; if ( needsEscape(ch, (i==N-1)) ) { escchar = true ; break ; } } if ( ! escchar ) return x ; StringBuilder sb = new StringBuilder(N+10) ; for ( int i = 0 ; i < N ; i++ ) { char ch = x.charAt(i) ; // DOT only needs escaping at the end if ( needsEscape(ch, (i==N-1) ) ) sb.append('\\') ; sb.append(ch) ; } return sb.toString() ; }