OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkString_DEFINED | 10 #ifndef SkString_DEFINED |
(...skipping 21 matching lines...) Expand all Loading... |
32 bool SkStrEndsWith(const char string[], const char suffixChar); | 32 bool SkStrEndsWith(const char string[], const char suffixChar); |
33 | 33 |
34 int SkStrStartsWithOneOf(const char string[], const char prefixes[]); | 34 int SkStrStartsWithOneOf(const char string[], const char prefixes[]); |
35 | 35 |
36 static int SkStrFind(const char string[], const char substring[]) { | 36 static int SkStrFind(const char string[], const char substring[]) { |
37 const char *first = strstr(string, substring); | 37 const char *first = strstr(string, substring); |
38 if (NULL == first) return -1; | 38 if (NULL == first) return -1; |
39 return SkToS32(first - &string[0]); | 39 return SkToS32(first - &string[0]); |
40 } | 40 } |
41 | 41 |
| 42 static int SkStrFindLastOf(const char string[], const char subchar) { |
| 43 const char* last = strrchr(string, subchar); |
| 44 if (NULL == last) return -1; |
| 45 return SkToS32(last - &string[0]); |
| 46 } |
| 47 |
42 static bool SkStrContains(const char string[], const char substring[]) { | 48 static bool SkStrContains(const char string[], const char substring[]) { |
43 SkASSERT(string); | 49 SkASSERT(string); |
44 SkASSERT(substring); | 50 SkASSERT(substring); |
45 return (-1 != SkStrFind(string, substring)); | 51 return (-1 != SkStrFind(string, substring)); |
46 } | 52 } |
47 static bool SkStrContains(const char string[], const char subchar) { | 53 static bool SkStrContains(const char string[], const char subchar) { |
48 SkASSERT(string); | 54 SkASSERT(string); |
49 char tmp[2]; | 55 char tmp[2]; |
50 tmp[0] = subchar; | 56 tmp[0] = subchar; |
51 tmp[1] = '\0'; | 57 tmp[1] = '\0'; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 151 } |
146 bool contains(const char substring[]) const { | 152 bool contains(const char substring[]) const { |
147 return SkStrContains(fRec->data(), substring); | 153 return SkStrContains(fRec->data(), substring); |
148 } | 154 } |
149 bool contains(const char subchar) const { | 155 bool contains(const char subchar) const { |
150 return SkStrContains(fRec->data(), subchar); | 156 return SkStrContains(fRec->data(), subchar); |
151 } | 157 } |
152 int find(const char substring[]) const { | 158 int find(const char substring[]) const { |
153 return SkStrFind(fRec->data(), substring); | 159 return SkStrFind(fRec->data(), substring); |
154 } | 160 } |
| 161 int findLastOf(const char subchar) const { |
| 162 return SkStrFindLastOf(fRec->data(), subchar); |
| 163 } |
155 | 164 |
156 friend bool operator==(const SkString& a, const SkString& b) { | 165 friend bool operator==(const SkString& a, const SkString& b) { |
157 return a.equals(b); | 166 return a.equals(b); |
158 } | 167 } |
159 friend bool operator!=(const SkString& a, const SkString& b) { | 168 friend bool operator!=(const SkString& a, const SkString& b) { |
160 return !a.equals(b); | 169 return !a.equals(b); |
161 } | 170 } |
162 | 171 |
163 // these methods edit the string | 172 // these methods edit the string |
164 | 173 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 // Specialized to take advantage of SkString's fast swap path. The unspecialized
function is | 263 // Specialized to take advantage of SkString's fast swap path. The unspecialized
function is |
255 // declared in SkTypes.h and called by SkTSort. | 264 // declared in SkTypes.h and called by SkTSort. |
256 template <> inline void SkTSwap(SkString& a, SkString& b) { | 265 template <> inline void SkTSwap(SkString& a, SkString& b) { |
257 a.swap(b); | 266 a.swap(b); |
258 } | 267 } |
259 | 268 |
260 // Split str on any characters in delimiters into out. (Think, strtok with a sa
ne API.) | 269 // Split str on any characters in delimiters into out. (Think, strtok with a sa
ne API.) |
261 void SkStrSplit(const char* str, const char* delimiters, SkTArray<SkString>* out
); | 270 void SkStrSplit(const char* str, const char* delimiters, SkTArray<SkString>* out
); |
262 | 271 |
263 #endif | 272 #endif |
OLD | NEW |