aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkStringUtils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkStringUtils.cpp')
-rw-r--r--src/core/SkStringUtils.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/core/SkStringUtils.cpp b/src/core/SkStringUtils.cpp
index 390de7f264..35e55570c3 100644
--- a/src/core/SkStringUtils.cpp
+++ b/src/core/SkStringUtils.cpp
@@ -35,3 +35,29 @@ void SkAppendScalar(SkString* str, SkScalar value, SkScalarAsStringType asType)
}
}
+SkString SkTabString(const SkString& string, int tabCnt) {
+ if (tabCnt <= 0) {
+ return string;
+ }
+ SkString tabs;
+ for (int i = 0; i < tabCnt; ++i) {
+ tabs.append("\t");
+ }
+ SkString result;
+ static const char newline[] = "\n";
+ const char* input = string.c_str();
+ int nextNL = SkStrFind(input, newline);
+ while (nextNL >= 0) {
+ if (nextNL > 0) {
+ result.append(tabs);
+ }
+ result.append(input, nextNL + 1);
+ input += nextNL + 1;
+ nextNL = SkStrFind(input, newline);
+ }
+ if (*input != '\0') {
+ result.append(tabs);
+ }
+ result.append(input);
+ return result;
+}