MCPcopy
hub / github.com/dianping/cat / format

Method format

lib/java/src/main/java/com/dianping/cat/util/UrlParser.java:24–75  ·  view source on GitHub ↗
(String url)

Source from the content-addressed store, hash-verified

22 private static final char SPLIT = '/';
23
24 public static String format(String url) {
25 int length = url.length();
26 StringBuilder sb = new StringBuilder(length);
27
28 for (int index = 0; index < length; ) {
29 char c = url.charAt(index);
30
31 if (c == SPLIT && index < length - 1) {
32 sb.append(c);
33
34 StringBuilder nextSection = new StringBuilder();
35 boolean isNumber = false;
36 boolean first = true;
37
38 for (int j = index + 1; j < length; j++) {
39 char next = url.charAt(j);
40
41 if ((first || isNumber) && next != SPLIT) {
42 isNumber = isNumber(next);
43 first = false;
44 }
45
46 if (next == SPLIT) {
47 if (isNumber) {
48 sb.append("{num}");
49 } else {
50 sb.append(nextSection.toString());
51 }
52 index = j;
53
54 break;
55 } else if (j == length - 1) {
56 if (isNumber) {
57 sb.append("{num}");
58 } else {
59 nextSection.append(next);
60 sb.append(nextSection.toString());
61 }
62 index = j + 1;
63 break;
64 } else {
65 nextSection.append(next);
66 }
67 }
68 } else {
69 sb.append(c);
70 index++;
71 }
72 }
73
74 return sb.toString();
75 }
76
77 private static boolean isNumber(char c) {
78 return (c >= '0' && c <= '9') || c == '.' || c == '-' || c == ',';

Callers 15

getRequestURIMethod · 0.95
initializeMethod · 0.45
resolveParameterValueMethod · 0.45
getParameterValueMethod · 0.45
getParameterValueMethod · 0.45
wrapsFunction · 0.45
addKVMethod · 0.45
date2strFunction · 0.45
buildMetricMessageMethod · 0.45
getServerConfigUrlMethod · 0.45

Calls 4

isNumberMethod · 0.95
lengthMethod · 0.45
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected