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

Method negateClass

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

Source from the content-addressed store, hash-verified

247
248 // negateClass() negates this CharClass, which must already be clean.
249 CharClass negateClass() {
250 int nextLo = 0; // lo end of next class to add
251 int w = 0; // write index
252 for (int i = 0; i < len; i += 2) {
253 int lo = r[i], hi = r[i + 1];
254 if (nextLo <= lo - 1) {
255 r[w] = nextLo;
256 r[w + 1] = lo - 1;
257 w += 2;
258 }
259 nextLo = hi + 1;
260 }
261 len = w;
262
263 if (nextLo <= Unicode.MAX_RUNE) {
264 // It's possible for the negation to have one more
265 // range - this one - than the original class, so use append.
266 ensureCapacity(len + 2);
267 r[len++] = nextLo;
268 r[len++] = Unicode.MAX_RUNE;
269 }
270 return this;
271 }
272
273 // appendClassWithSign() calls appendClass() if sign is +1 or
274 // appendNegatedClass if sign is -1. Does not mutate |x|.

Callers 2

parseClassMethod · 0.95
testNegateClassMethod · 0.80

Calls 1

ensureCapacityMethod · 0.95

Tested by 1

testNegateClassMethod · 0.64