MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / encodeString

Method encodeString

vm/JavaAPI/src/java/net/URIHelper.java:216–241  ·  view source on GitHub ↗

Utility method to encode a string, as per RFC 2396 section 2. Set asQueryValue=false to avoid encoding ampersands. @param source @return @see http://www.ietf.org/rfc/rfc2396.txt

(String source)

Source from the content-addressed store, hash-verified

214 * @see <a href="http://www.ietf.org/rfc/rfc2396.txt">http://www.ietf.org/rfc/rfc2396.txt</a>
215 */
216 public static String encodeString(String source) { // , boolean
217 // asQueryValue) {
218 if (source == null) {
219 return source;
220 }
221 int i = firstIllegalCharacter(source);
222 // most strings not encoded, so prevent extra objects and work.
223 if (i == -1) {
224 return source;
225 }
226 StringBuffer encoded = new StringBuffer();
227 encoded.append(source.substring(0, i));
228 byte bytes[] = toBytes(source);
229 for (; i < bytes.length; i++) {
230 int ch = bytes[i];
231 // if (ch == URI.QUERY_SEPARATOR && asQueryValue) {
232 // encoded.append(ENCODED_AMPERSAND);
233 // } else
234 if (isLegal(ch)) {
235 encoded.append((char) ch);
236 } else {
237 encoded.append(QUOTE_MARKER + Integer.toHexString((byte) ch & 0xff).toUpperCase());
238 }
239 }
240 return encoded.toString();
241 }
242
243 /**
244 * Internal use only, for sources known to always be valid.

Callers 5

setAuthorityMethod · 0.95
setQueryMethod · 0.95
setPathMethod · 0.95
setFragmentMethod · 0.95
invokeStatic3Method · 0.45

Calls 8

firstIllegalCharacterMethod · 0.95
appendMethod · 0.95
toBytesMethod · 0.95
isLegalMethod · 0.95
toHexStringMethod · 0.95
toStringMethod · 0.95
substringMethod · 0.65
toUpperCaseMethod · 0.65

Tested by

no test coverage detected