Parses a character class name like [:alnum:]. Sets *s to span the remainder of the string. Adds the ranges corresponding to the class to ranges.
| 1818 | // Sets *s to span the remainder of the string. |
| 1819 | // Adds the ranges corresponding to the class to ranges. |
| 1820 | static ParseStatus ParseCCName(StringPiece* s, Regexp::ParseFlags parse_flags, |
| 1821 | CharClassBuilder *cc, |
| 1822 | RegexpStatus* status) { |
| 1823 | // Check begins with [: |
| 1824 | const char* p = s->data(); |
| 1825 | const char* ep = s->data() + s->size(); |
| 1826 | if (ep - p < 2 || p[0] != '[' || p[1] != ':') |
| 1827 | return kParseNothing; |
| 1828 | |
| 1829 | // Look for closing :]. |
| 1830 | const char* q; |
| 1831 | for (q = p+2; q <= ep-2 && (*q != ':' || *(q+1) != ']'); q++) |
| 1832 | ; |
| 1833 | |
| 1834 | // If no closing :], then ignore. |
| 1835 | if (q > ep-2) |
| 1836 | return kParseNothing; |
| 1837 | |
| 1838 | // Got it. Check that it's valid. |
| 1839 | q += 2; |
| 1840 | StringPiece name(p, static_cast<size_t>(q - p)); |
| 1841 | |
| 1842 | const UGroup *g = LookupPosixGroup(name); |
| 1843 | if (g == NULL) { |
| 1844 | status->set_code(kRegexpBadCharRange); |
| 1845 | status->set_error_arg(name); |
| 1846 | return kParseError; |
| 1847 | } |
| 1848 | |
| 1849 | s->remove_prefix(name.size()); |
| 1850 | AddUGroup(cc, g, g->sign, parse_flags); |
| 1851 | return kParseOk; |
| 1852 | } |
| 1853 | |
| 1854 | // Parses a character inside a character class. |
| 1855 | // There are fewer special characters here than in the rest of the regexp. |
no test coverage detected