| 882 | } |
| 883 | |
| 884 | void CharClassBuilder::Negate() { |
| 885 | // Build up negation and then copy in. |
| 886 | // Could edit ranges in place, but C++ won't let me. |
| 887 | std::vector<RuneRange> v; |
| 888 | v.reserve(ranges_.size() + 1); |
| 889 | |
| 890 | // In negation, first range begins at 0, unless |
| 891 | // the current class begins at 0. |
| 892 | iterator it = begin(); |
| 893 | if (it == end()) { |
| 894 | v.push_back(RuneRange(0, Runemax)); |
| 895 | } else { |
| 896 | int nextlo = 0; |
| 897 | if (it->lo == 0) { |
| 898 | nextlo = it->hi + 1; |
| 899 | ++it; |
| 900 | } |
| 901 | for (; it != end(); ++it) { |
| 902 | v.push_back(RuneRange(nextlo, it->lo - 1)); |
| 903 | nextlo = it->hi + 1; |
| 904 | } |
| 905 | if (nextlo <= Runemax) |
| 906 | v.push_back(RuneRange(nextlo, Runemax)); |
| 907 | } |
| 908 | |
| 909 | ranges_.clear(); |
| 910 | for (size_t i = 0; i < v.size(); i++) |
| 911 | ranges_.insert(v[i]); |
| 912 | |
| 913 | upper_ = AlphaMask & ~upper_; |
| 914 | lower_ = AlphaMask & ~lower_; |
| 915 | nrunes_ = Runemax+1 - nrunes_; |
| 916 | } |
| 917 | |
| 918 | // Character class is a sorted list of ranges. |
| 919 | // The ranges are allocated in the same block as the header, |