For each character in characters_wanted, sets the index corresponding to the ASCII code of that character to 1 in table. This is used by the find_.*_of methods below to tell whether or not a character is in the lookup table in constant time. The argument `table' must be an array that is large enough to hold all the possible values of an unsigned char. Thus it should be be declared as follows: bo
| 116 | // as follows: |
| 117 | // bool table[UCHAR_MAX + 1] |
| 118 | static inline void BuildLookupTable(StringPiece characters_wanted, |
| 119 | bool* table) { |
| 120 | const int length = characters_wanted.length(); |
| 121 | const char* const data = characters_wanted.data(); |
| 122 | for (int i = 0; i < length; ++i) { |
| 123 | table[static_cast<unsigned char>(data[i])] = true; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | int StringPiece::find_first_of(StringPiece s, size_type pos) const { |
| 128 | if (length_ <= 0 || s.length_ <= 0) { |
no test coverage detected