------------------------------------------------------------------------ FindNth() return index of nth occurrence of c in the string, or string::npos if n > number of occurrences of c. (returns string::npos = -1 if n <= 0) ------------------------------------------------------------------------
| 1025 | // (returns string::npos = -1 if n <= 0) |
| 1026 | //------------------------------------------------------------------------ |
| 1027 | int FindNth(StringPiece s, char c, int n) { |
| 1028 | size_t pos = string::npos; |
| 1029 | |
| 1030 | for ( int i = 0; i < n; ++i ) { |
| 1031 | pos = s.find_first_of(c, pos + 1); |
| 1032 | if ( pos == StringPiece::npos ) { |
| 1033 | break; |
| 1034 | } |
| 1035 | } |
| 1036 | return pos; |
| 1037 | } |
| 1038 | |
| 1039 | //------------------------------------------------------------------------ |
| 1040 | // ReverseFindNth() |
nothing calls this directly
no test coverage detected