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

Method asciiAuthority

basex-core/src/main/java/org/basex/io/IOUrl.java:321–336  ·  view source on GitHub ↗

Returns the authority with the host part converted to ASCII (Punycode). @param authority authority string ([userinfo@]host[:port]) @return ASCII-encoded authority, or the original string if encoding fails

(final String authority)

Source from the content-addressed store, hash-verified

319 * @return ASCII-encoded authority, or the original string if encoding fails
320 */
321 private static String asciiAuthority(final String authority) {
322 final int at = authority.indexOf('@');
323 final String userInfo = at < 0 ? "" : authority.substring(0, at + 1);
324 final String hostPort = at < 0 ? authority : authority.substring(at + 1);
325 // skip IPv6 brackets when searching for the port colon
326 final int bracket = hostPort.lastIndexOf(']');
327 final int colon = hostPort.indexOf(':', Math.max(0, bracket));
328 final String host = colon < 0 ? hostPort : hostPort.substring(0, colon);
329 final String port = colon < 0 ? "" : hostPort.substring(colon);
330 try {
331 return userInfo + IDN.toASCII(host) + port;
332 } catch(final IllegalArgumentException ex) {
333 Util.debug(ex);
334 return authority;
335 }
336 }
337}

Callers 1

toAsciiMethod · 0.95

Calls 5

debugMethod · 0.95
lastIndexOfMethod · 0.80
indexOfMethod · 0.45
substringMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected