Index: src/core/SkString.cpp |
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp |
index d93f662da3d8bc0a80ca96903752bbcc3977ba1e..b5655e0503be9574f93047dc54f9158b343c25fc 100644 |
--- a/src/core/SkString.cpp |
+++ b/src/core/SkString.cpp |
@@ -624,16 +624,35 @@ SkString SkStringPrintf(const char* format, ...) { |
return formattedOutput; |
} |
-void SkStrSplit(const char* str, const char* delimiters, SkTArray<SkString>* out) { |
- const char* end = str + strlen(str); |
- while (str != end) { |
- // Find a token. |
- const size_t len = strcspn(str, delimiters); |
- out->push_back().set(str, len); |
- str += len; |
+void SkStrSplit(const char* str, const char* delimiters, SkStrSplitMode splitMode, |
+ SkTArray<SkString>* out) { |
+ if (splitMode == kCoalesce_SkStrSplitMode) { |
// Skip any delimiters. |
str += strspn(str, delimiters); |
} |
+ if (!*str) { |
+ return; |
+ } |
+ |
+ while (true) { |
+ // Find a token. |
+ const size_t len = strcspn(str, delimiters); |
+ if (splitMode == kStrict_SkStrSplitMode || len > 0) { |
+ out->push_back().set(str, len); |
+ str += len; |
+ } |
+ |
+ if (!*str) { |
+ return; |
+ } |
+ if (splitMode == kCoalesce_SkStrSplitMode) { |
+ // Skip any delimiters. |
+ str += strspn(str, delimiters); |
+ } else { |
+ // Skip one delimiter. |
+ str += 1; |
+ } |
+ } |
} |
#undef VSNPRINTF |