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

Method normPath

basex-core/src/main/java/org/basex/data/MetaData.java:164–187  ·  view source on GitHub ↗

Normalizes a database path. Converts backslashes and removes duplicate and leading slashes. Returns null if the path contains invalid characters. @param path input path @return normalized path or null

(final String path)

Source from the content-addressed store, hash-verified

162 * @return normalized path or {@code null}
163 */
164 public static String normPath(final String path) {
165 // scan path segments
166 final StringList list = new StringList();
167 final StringBuilder sb = new StringBuilder();
168 final int pl = path.length();
169 for(int p = 0; p < pl; p++) {
170 final char ch = path.charAt(p);
171 if(ch == '\\' || ch == '/') {
172 if(!addToPath(sb, list)) return null;
173 } else {
174 if(Prop.WIN && ":*?\"<>\\|".indexOf(ch) != -1) return null;
175 sb.append(ch);
176 }
177 }
178 if(!addToPath(sb, list)) return null;
179 sb.append(String.join("/", list.finish()));
180
181 // add trailing slash
182 if(pl > 0 && !sb.isEmpty()) {
183 final char ch = path.charAt(pl - 1);
184 if(ch == '\\' || ch == '/') sb.append('/');
185 }
186 return sb.toString();
187 }
188
189 /**
190 * Adds a segment to the path if it is valid.

Callers 15

runMethod · 0.95
buildMethod · 0.95
runMethod · 0.95
runMethod · 0.95
runMethod · 0.95
runMethod · 0.95
runMethod · 0.95
runMethod · 0.95
toDbPathMethod · 0.95
resourcesMethod · 0.95
docsMethod · 0.95
docMethod · 0.95

Calls 9

addToPathMethod · 0.95
charAtMethod · 0.80
appendMethod · 0.65
toStringMethod · 0.65
lengthMethod · 0.45
indexOfMethod · 0.45
joinMethod · 0.45
finishMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected