MCPcopy Create free account
hub / github.com/google/re2j / cleanClass

Method cleanClass

java/com/google/re2j/CharClass.java:66–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64 // cleanClass() sorts the ranges (pairs of elements) of this CharClass,
65 // merges them, and eliminates duplicates.
66 CharClass cleanClass() {
67 if (len < 4) {
68 return this;
69 }
70
71 // Sort by lo increasing, hi decreasing to break ties.
72 qsortIntPair(r, 0, len - 2);
73
74 // Merge abutting, overlapping.
75 int w = 2; // write index
76 for (int i = 2; i < len; i += 2) {
77 int lo = r[i];
78 int hi = r[i + 1];
79 if (lo <= r[w - 1] + 1) {
80 // merge with previous range
81 if (hi > r[w - 1]) {
82 r[w - 1] = hi;
83 }
84 continue;
85 }
86 // new disjoint range
87 r[w] = lo;
88 r[w + 1] = hi;
89 w += 2;
90 }
91 len = w;
92
93 return this;
94 }
95
96 // appendLiteral() appends the literal |x| to this CharClass.
97 CharClass appendLiteral(int x, int flags) {

Callers 5

parseClassMethod · 0.95
testCleanClassMethod · 0.80
appendGroupMethod · 0.80
cleanAltMethod · 0.80
parseUnicodeClassMethod · 0.80

Calls 1

qsortIntPairMethod · 0.95

Tested by 1

testCleanClassMethod · 0.64