/** *URLEncodestring,usingaspecifiedencoding. * *@paramsstringtobeencoded *@paramstartthebeginningindex,inclusive *@paramendtheendingindex,exclusive * *@returnAnewCharChunkcontainedtheURLencodedstring * *@throwsIOExceptionIfanI/Oerroroccurs
*/ public CharChunk encodeURL(String s, int start, int end) throws IOException { if (c2b == null) {
bb = new ByteChunk(8); // small enough.
cb = new CharChunk(2); // small enough.
output = new CharChunk(64); // small enough.
c2b = new C2BConverter(StandardCharsets.UTF_8);
} else {
bb.recycle();
cb.recycle();
output.recycle();
}
for (int i = start; i < end; i++) { char c = s.charAt(i); if (safeChars.get(c)) {
output.append(c);
} else {
cb.append(c);
c2b.convert(cb, bb);
// "surrogate" - UTF is _not_ 16 bit, but 21 !!!! // ( while UCS is 31 ). Amazing... if (c >= 0xD800 && c <= 0xDBFF) { if ((i + 1) < end) { char d = s.charAt(i + 1); if (d >= 0xDC00 && d <= 0xDFFF) {
cb.append(d);
c2b.convert(cb, bb);
i++;
}
}
* The ASFlicenses this file to You under the Apache License, Version 2.0
privatestatic BitSet initialSafeChars() {
BitSet initialSafeChars = new BitSet(128); int i; for (i = 'a'; i <= 'z'; i++) {
initialSafeChars.set(i);
} for (i = 'A'; i <= 'Z'; i++) {
initialSafeChars.set(i);
} for (i = '0'; i <= '9'; i++) {
initialSafeChars.set(i);
} // safe
initialSafeChars.set('$');
initialSafeChars.set('-');
initialSafeChars.set('_');
initialSafeChars.set('.');
// Dangerous: someone may treat this as " " // RFC1738 does allow it, it's not reserved // initialSafeChars.set('+'); // extra
initialSafeChars.set('!');
initialSafeChars.set('*');
initialSafeChars.set('\'');
initialSafeChars.set('(');
initialSafeChars.set(')');
initialSafeChars.set(','); return initialSafeChars;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.