| 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 |
#ifndef SkStringUtils_DEFINED |
| 9 |
#define SkStringUtils_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkScalar.h" |
| 12 |
#include "include/core/SkString.h" |
| 13 |
#include "include/private/base/SkTArray.h" |
| 14 |
|
| 15 |
#include <cstddef> |
| 16 |
#include <cstdint> |
| 17 |
|
| 18 |
enum SkScalarAsStringType { |
| 19 |
kDec_SkScalarAsStringType, |
| 20 |
kHex_SkScalarAsStringType, |
| 21 |
}; |
| 22 |
|
| 23 |
void SkAppendScalar(SkString*, SkScalar, SkScalarAsStringType); |
| 24 |
|
| 25 |
static inline void SkAppendScalarDec(SkString* str, SkScalar value) { |
| 26 |
SkAppendScalar(str, value, kDec_SkScalarAsStringType); |
| 27 |
} |
| 28 |
|
| 29 |
static inline void SkAppendScalarHex(SkString* str, SkScalar value) { |
| 30 |
SkAppendScalar(str, value, kHex_SkScalarAsStringType); |
| 31 |
} |
| 32 |
|
| 33 |
/** Indents every non-empty line of the string by tabCnt tabs */ |
| 34 |
SkString SkTabString(const SkString& string, int tabCnt); |
| 35 |
|
| 36 |
SkString SkStringFromUTF16(const uint16_t* src, size_t count); |
| 37 |
|
| 38 |
#if defined(SK_BUILD_FOR_WIN) |
| 39 |
#define SK_strcasecmp _stricmp |
| 40 |
#else |
| 41 |
#define SK_strcasecmp strcasecmp |
| 42 |
#endif |
| 43 |
|
| 44 |
enum SkStrSplitMode { |
| 45 |
// Strictly return all results. If the input is ",," and the separator is ',' this will return |
| 46 |
// an array of three empty strings. |
| 47 |
kStrict_SkStrSplitMode, |
| 48 |
|
| 49 |
// Only nonempty results will be added to the results. Multiple separators will be |
| 50 |
// coalesced. Separators at the beginning and end of the input will be ignored. If the input is |
| 51 |
// ",," and the separator is ',', this will return an empty vector. |
| 52 |
kCoalesce_SkStrSplitMode |
| 53 |
}; |
| 54 |
|
| 55 |
// Split str on any characters in delimiters into out. (strtok with a non-destructive API.) |
| 56 |
void SkStrSplit(const char* str, |
| 57 |
const char* delimiters, |
| 58 |
SkStrSplitMode splitMode, |
| 59 |
skia_private::TArray<SkString>* out); |
| 60 |
|
| 61 |
inline void SkStrSplit( |
| 62 |
const char* str, const char* delimiters, skia_private::TArray<SkString>* out) { |
| 63 |
SkStrSplit(str, delimiters, kCoalesce_SkStrSplitMode, out); |
| 64 |
} |
| 65 |
|
| 66 |
#endif |