Source:
private static int parseTemplate(String template, String[] urlPieces, int[] identifiers, String[] identifierFormatTags) { template = template.replace("%00","%0"); urlPieces[0] = ""; int templateIndex = 0; int identifierCount = 0; while (templateIndex < template.length()) { int dollarIndex = template.indexOf("$", templateIndex); if (dollarIndex == -1) { urlPieces[identifierCount] += template.substring(templateIndex); templateIndex = template.length(); } else if (dollarIndex != templateIndex) { urlPieces[identifierCount] += template.substring(templateIndex, dollarIndex); templateIndex = dollarIndex; } else if (template.startsWith(ESCAPED_DOLLAR, templateIndex)) { urlPieces[identifierCount] += "$"; templateIndex += 2; } else { int secondIndex = template.indexOf("$", templateIndex + 1); String identifier = template.substring(templateIndex + 1, secondIndex); if (identifier.equals(REPRESENTATION)) { identifiers[identifierCount] = REPRESENTATION_ID; } else { int formatTagIndex = identifier.indexOf("%0"); String formatTag = DEFAULT_FORMAT_TAG; if (formatTagIndex != -1) { formatTag = identifier.substring(formatTagIndex); if (!formatTag.endsWith("d") && !formatTag.endsWith("x")) { formatTag += "d"; } identifier = identifier.substring(0, formatTagIndex); } switch (identifier) { case NUMBER: identifiers[identifierCount] = NUMBER_ID; break; case BANDWIDTH: identifiers[identifierCount] = BANDWIDTH_ID; break; case TIME: identifiers[identifierCount] = TIME_ID; break; default: throw new IllegalArgumentException("Invalid template: " + template); } identifierFormatTags[identifierCount] = formatTag; } identifierCount++; urlPieces[identifierCount] = ""; templateIndex = secondIndex + 1; } } return identifierCount; }

Target:
private static int parseTemplate(String template, String[] urlPieces, int[] identifiers, String[] identifierFormatTags) { template = template.replace("%00d",""); urlPieces[0] = ""; int templateIndex = 0; int identifierCount = 0; while (templateIndex < template.length()) { int dollarIndex = template.indexOf("$", templateIndex); if (dollarIndex == -1) { urlPieces[identifierCount] += template.substring(templateIndex); templateIndex = template.length(); } else if (dollarIndex != templateIndex) { urlPieces[identifierCount] += template.substring(templateIndex, dollarIndex); templateIndex = dollarIndex; } else if (template.startsWith(ESCAPED_DOLLAR, templateIndex)) { urlPieces[identifierCount] += "$"; templateIndex += 2; } else { int secondIndex = template.indexOf("$", templateIndex + 1); String identifier = template.substring(templateIndex + 1, secondIndex); if (identifier.equals(REPRESENTATION)) { identifiers[identifierCount] = REPRESENTATION_ID; } else { int formatTagIndex = identifier.indexOf("%0"); String formatTag = DEFAULT_FORMAT_TAG; if (formatTagIndex != -1) { formatTag = identifier.substring(formatTagIndex); if (!formatTag.endsWith("d") && !formatTag.endsWith("x")) { formatTag += "d"; } identifier = identifier.substring(0, formatTagIndex); } switch (identifier) { case NUMBER: identifiers[identifierCount] = NUMBER_ID; break; case BANDWIDTH: identifiers[identifierCount] = BANDWIDTH_ID; break; case TIME: identifiers[identifierCount] = TIME_ID; break; default: throw new IllegalArgumentException("Invalid template: " + template); } identifierFormatTags[identifierCount] = formatTag; } identifierCount++; urlPieces[identifierCount] = ""; templateIndex = secondIndex + 1; } } return identifierCount; }