Line data Source code
1 : /*
2 : * Copyright 2013 Google Inc.
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 : #include "SkString.h"
9 : #include "SkStringUtils.h"
10 :
11 0 : void SkAddFlagToString(SkString* string, bool flag, const char* flagStr, bool* needSeparator) {
12 0 : if (flag) {
13 0 : if (*needSeparator) {
14 0 : string->append("|");
15 : }
16 0 : string->append(flagStr);
17 0 : *needSeparator = true;
18 : }
19 0 : }
20 :
21 0 : void SkAppendScalar(SkString* str, SkScalar value, SkScalarAsStringType asType) {
22 0 : switch (asType) {
23 : case kHex_SkScalarAsStringType:
24 0 : str->appendf("SkBits2Float(0x%08x)", SkFloat2Bits(value));
25 0 : break;
26 : case kDec_SkScalarAsStringType: {
27 0 : SkString tmp;
28 0 : tmp.printf("%g", value);
29 0 : if (tmp.contains('.')) {
30 0 : tmp.appendUnichar('f');
31 : }
32 0 : str->append(tmp);
33 0 : break;
34 : }
35 : }
36 0 : }
37 :
38 0 : SkString SkTabString(const SkString& string, int tabCnt) {
39 0 : if (tabCnt <= 0) {
40 0 : return string;
41 : }
42 0 : SkString tabs;
43 0 : for (int i = 0; i < tabCnt; ++i) {
44 0 : tabs.append("\t");
45 : }
46 0 : SkString result;
47 : static const char newline[] = "\n";
48 0 : const char* input = string.c_str();
49 0 : int nextNL = SkStrFind(input, newline);
50 0 : while (nextNL >= 0) {
51 0 : if (nextNL > 0) {
52 0 : result.append(tabs);
53 : }
54 0 : result.append(input, nextNL + 1);
55 0 : input += nextNL + 1;
56 0 : nextNL = SkStrFind(input, newline);
57 : }
58 0 : if (*input != '\0') {
59 0 : result.append(tabs);
60 0 : result.append(input);
61 : }
62 0 : return result;
63 : }
|