| 100 | |
| 101 | // appendRange() appends the range [lo-hi] (inclusive) to this CharClass. |
| 102 | CharClass appendRange(int lo, int hi) { |
| 103 | // Expand last range or next to last range if it overlaps or abuts. |
| 104 | // Checking two ranges helps when appending case-folded |
| 105 | // alphabets, so that one range can be expanding A-Z and the |
| 106 | // other expanding a-z. |
| 107 | if (len > 0) { |
| 108 | for (int i = 2; i <= 4; i += 2) { // twice, using i=2, i=4 |
| 109 | if (len >= i) { |
| 110 | int rlo = r[len - i]; |
| 111 | int rhi = r[len - i + 1]; |
| 112 | if (lo <= rhi + 1 && rlo <= hi + 1) { |
| 113 | if (lo < rlo) { |
| 114 | r[len - i] = lo; |
| 115 | } |
| 116 | if (hi > rhi) { |
| 117 | r[len - i + 1] = hi; |
| 118 | } |
| 119 | return this; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | // Can't coalesce; append. Expand capacity by doubling as needed. |
| 125 | ensureCapacity(len + 2); |
| 126 | r[len++] = lo; |
| 127 | r[len++] = hi; |
| 128 | return this; |
| 129 | } |
| 130 | |
| 131 | // appendFoldedRange() appends the range [lo-hi] and its case |
| 132 | // folding-equivalent runes to this CharClass. |