| 41 | // StringPiece::find_first_of(). |
| 42 | template <typename FindPolicy> |
| 43 | StringPiece GenericFind( |
| 44 | StringPiece text, |
| 45 | StringPiece delimiter, |
| 46 | FindPolicy find_policy) { |
| 47 | if (delimiter.empty() && text.length() > 0) { |
| 48 | // Special case for empty string delimiters: always return a zero-length |
| 49 | // StringPiece referring to the item at position 1. |
| 50 | return StringPiece(text.begin() + 1, 0); |
| 51 | } |
| 52 | int found_pos = StringPiece::npos; |
| 53 | StringPiece found(text.end(), 0); // By default, not found |
| 54 | found_pos = find_policy.Find(text, delimiter); |
| 55 | if (found_pos != StringPiece::npos) { |
| 56 | found.set(text.data() + found_pos, find_policy.Length(delimiter)); |
| 57 | } |
| 58 | return found; |
| 59 | } |
| 60 | |
| 61 | // Finds using StringPiece::find(), therefore the length of the found delimiter |
| 62 | // is delimiter.length(). |