MCPcopy Create free account
hub / github.com/BaseXdb/basex / normalize

Method normalize

basex-core/src/main/java/org/basex/util/Token.java:1203–1235  ·  view source on GitHub ↗

Normalizes all whitespace occurrences from the specified token. @param token token @return normalized token

(final byte[] token)

Source from the content-addressed store, hash-verified

1201 * @return normalized token
1202 */
1203 public static byte[] normalize(final byte[] token) {
1204 final int tl = token.length;
1205 int s = 0, e = tl - 1;
1206 while(s <= e && ws(token[s])) s++;
1207 while(e > s && ws(token[e])) e--;
1208 if(s > e) return EMPTY;
1209
1210 int size = 0;
1211 boolean inWs = false, replace = false;
1212 for(int i = s; i <= e; i++) {
1213 final byte b = token[i];
1214 final boolean ws = ws(token[i]);
1215 if(!(ws && inWs)) {
1216 size++;
1217 inWs = ws;
1218 if(ws && b != ' ') replace = true;
1219 }
1220 }
1221 if(size == tl && !replace) return token;
1222
1223 final byte[] tmp = new byte[size];
1224 int c = 0;
1225 inWs = false;
1226 for(int i = s; i <= e; i++) {
1227 final byte b = token[i];
1228 final boolean ws = ws(b);
1229 if(!(ws && inWs)) {
1230 tmp[c++] = ws ? (byte) ' ' : b;
1231 inWs = ws;
1232 }
1233 }
1234 return tmp;
1235 }
1236
1237 /**
1238 * Checks if the specified character is a whitespace (0x09, 0x0A, 0x0D, 0x20).

Callers 13

textMethod · 0.95
attributeMethod · 0.95
optPredMethod · 0.95
inputMethod · 0.95
itemMethod · 0.95
emptyMethod · 0.95
mixedMethod · 0.95
itemMethod · 0.95
valueMethod · 0.95
getMethod · 0.95
eqMethod · 0.95
distinctTokensMethod · 0.95

Calls 4

wsMethod · 0.95
asciiMethod · 0.95
tokenMethod · 0.95
stringMethod · 0.95

Tested by

no test coverage detected