diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-03-31 09:33:41 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-31 15:25:32 +0000 |
commit | f3333c89bf05fc602d9bf8e1e24547668c660383 (patch) | |
tree | 3c0855ef8829201299ce757ecaf28bfda50a2683 /src/sksl/SkSLString.h | |
parent | 66b09abdb184d843ece45a1d343fbe632075b323 (diff) |
skslc can now be compiled with no Skia dependencies, in preparation for its eventual
role in Skia's build process.
This reverts commit bcf35f86d50b784b165de703b404998dd4299f6a.
BUG=skia:
Change-Id: Id0a12dfc4d804d69a3c6bf60fed37e89ee130f02
Reviewed-on: https://skia-review.googlesource.com/10802
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Diffstat (limited to 'src/sksl/SkSLString.h')
-rw-r--r-- | src/sksl/SkSLString.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/sksl/SkSLString.h b/src/sksl/SkSLString.h new file mode 100644 index 0000000000..73ba74643e --- /dev/null +++ b/src/sksl/SkSLString.h @@ -0,0 +1,105 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SKSL_STRING +#define SKSL_STRING + + +#ifdef SKSL_STANDALONE + #define SKSL_STRING_BASE std::string + #include <string> +#else + #define SKSL_STRING_BASE SkString + #include "SkString.h" +#endif + +namespace SkSL { + +class String : public SKSL_STRING_BASE { +public: + String() = default; + String(const String&) = default; + String(String&&) = default; + String& operator=(const String&) = default; + String& operator=(String&&) = default; + +#ifndef SKSL_STANDALONE + String(const SkString& s) + : INHERITED(s) {} +#endif + + String(const char* s) + : INHERITED(s) {} + + String(const char* s, size_t size) + : INHERITED(s, size) {} + + static String printf(const char* fmt, ...); + +#ifdef SKSL_STANDALONE + void appendf(const char* fmt, ...); +#endif + void vappendf(const char* fmt, va_list va); + + bool startsWith(const char* s) const; + bool endsWith(const char* s) const; + + String operator+(const char* s) const; + String operator+(const String& s) const; + bool operator==(const char* s) const; + bool operator!=(const char* s) const; + bool operator==(const String& s) const; + bool operator!=(const String& s) const; + friend String operator+(const char* s1, const String& s2); + friend bool operator==(const char* s1, const String& s2); + friend bool operator!=(const char* s1, const String& s2); + +private: + typedef SKSL_STRING_BASE INHERITED; +}; + +String operator+(const char* s1, const String& s2); +bool operator!=(const char* s1, const String& s2); + +String to_string(double value); + +String to_string(int32_t value); + +String to_string(uint32_t value); + +String to_string(int64_t value); + +String to_string(uint64_t value); + +int stoi(String s); + +double stod(String s); + +long stol(String s); + +} // namespace + +#ifdef SKSL_STANDALONE +namespace std { + template<> struct hash<SkSL::String> { + size_t operator()(const SkSL::String& s) const { + return hash<std::string>{}(s); + } + }; +} // namespace +#else +#include "SkOpts.h" +namespace std { + template<> struct hash<SkSL::String> { + size_t operator()(const SkSL::String& s) const { + return SkOpts::hash_fn(s.c_str(), s.size(), 0); + } + }; +} // namespace +#endif // SKIA_STANDALONE + +#endif |