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

Method decodeEntity

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

Decode an HTML encoded entity. @param source @return 0 if the value is not an encoded entity

(String source)

Source from the content-addressed store, hash-verified

147 * @return 0 if the value is not an encoded entity
148 */
149 static char decodeEntity(String source) {
150 if (source.length() < 4 || source.charAt(0) != HTML_ENTITY_START
151 || source.charAt(source.length() - 1) != HTML_ENTITY_TERMINATE) {
152 return HTML_ENTITY_INVALID;
153 }
154 // Handle entities by value
155 if (source.charAt(1) == HTML_ENTITY_RAWVALUE) {
156 try {
157 if (Character.toLowerCase(source.charAt(2)) == HTML_ENTITY_RAWHEXVALUE) {
158 return (char) Integer.parseInt(source.substring(3, 4), 16);
159 } else {
160 return (char) Integer.parseInt(source.substring(2, 3), 10);
161 }
162 } catch (NumberFormatException nfe) {
163 return HTML_ENTITY_INVALID;
164 }
165 }
166 // Handle entities by alias
167 source = source.toLowerCase();
168 for (int i = 0; i < HTML_ENCODED_ENTITIES.length; i++) {
169 if (source.equals(HTML_ENCODED_ENTITIES[i])) {
170 return HTML_ENTITIES[i];
171 }
172 }
173 return HTML_ENTITY_INVALID;
174 }
175
176 /**
177 * Encode an HTML entity.

Callers 1

nextTokenMethod · 0.45

Calls 7

toLowerCaseMethod · 0.95
parseIntMethod · 0.95
lengthMethod · 0.65
charAtMethod · 0.65
substringMethod · 0.65
toLowerCaseMethod · 0.65
equalsMethod · 0.65

Tested by

no test coverage detected