diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2016-11-21 10:39:35 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2016-11-21 17:14:43 +0000 |
commit | 9e1138d56665d13641f8805cd72ae81adc255f79 (patch) | |
tree | 1c94ded7cff10f5f62233d1de83c3d30ad0a2893 /src/sksl/SkSLUtil.cpp | |
parent | e54d4cefb7864a575c01894b2e5e0df16978c6e6 (diff) |
re-land of switched skslc from std::string to SkString
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5084
Change-Id: Ib21c30afc0d8483392b417e660b7fecfcc30e617
Reviewed-on: https://skia-review.googlesource.com/5084
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLUtil.cpp')
-rw-r--r-- | src/sksl/SkSLUtil.cpp | 92 |
1 files changed, 65 insertions, 27 deletions
diff --git a/src/sksl/SkSLUtil.cpp b/src/sksl/SkSLUtil.cpp index 51ad9fe808..98e5fa4599 100644 --- a/src/sksl/SkSLUtil.cpp +++ b/src/sksl/SkSLUtil.cpp @@ -7,61 +7,66 @@ #include "SkSLUtil.h" +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif +#include <cinttypes> + namespace SkSL { -std::string to_string(double value) { - std::stringstream buffer; - buffer << std::setprecision(std::numeric_limits<double>::digits10) << value; - std::string result = buffer.str(); - if (result.find_last_of(".") == std::string::npos && - result.find_last_of("e") == std::string::npos) { +SkString to_string(double value) { +#ifdef SK_BUILD_FOR_WIN + #define SNPRINTF _snprintf +#else + #define SNPRINTF snprintf +#endif +#define MAX_DOUBLE_CHARS 25 + char buffer[MAX_DOUBLE_CHARS]; + SkDEBUGCODE(int len = )SNPRINTF(buffer, sizeof(buffer), "%.17g", value); + ASSERT(len < MAX_DOUBLE_CHARS); + SkString result(buffer); + if (!strchr(buffer, '.') && !strchr(buffer, 'e')) { result += ".0"; } return result; +#undef SNPRINTF +#undef MAX_DOUBLE_CHARS } -std::string to_string(int32_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(int32_t value) { + return SkStringPrintf("%d", value); } -std::string to_string(uint32_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(uint32_t value) { + return SkStringPrintf("%u", value); } -std::string to_string(int64_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(int64_t value) { + return SkStringPrintf("%" PRId64, value); } -std::string to_string(uint64_t value) { - std::stringstream buffer; - buffer << value; - return buffer.str(); +SkString to_string(uint64_t value) { + return SkStringPrintf("%" PRIu64, value); } -int stoi(std::string s) { +int stoi(SkString s) { if (s.size() > 2 && s[0] == '0' && s[1] == 'x') { char* p; - int result = strtoul(s.substr(2).c_str(), &p, 16); + int result = strtoul(s.c_str() + 2, &p, 16); ASSERT(*p == 0); return result; } return atoi(s.c_str()); } -double stod(std::string s) { +double stod(SkString s) { return atof(s.c_str()); } -long stol(std::string s) { +long stol(SkString s) { if (s.size() > 2 && s[0] == '0' && s[1] == 'x') { char* p; - long result = strtoul(s.substr(2).c_str(), &p, 16); + long result = strtoul(s.c_str() + 2, &p, 16); ASSERT(*p == 0); return result; } @@ -77,4 +82,37 @@ void sksl_abort() { #endif } +void write_data(const SkData& data, SkWStream& out) { + out.write(data.data(), data.size()); +} + +SkString operator+(const SkString& s, const char* c) { + SkString result(s); + result += c; + return result; +} + +SkString operator+(const char* c, const SkString& s) { + SkString result(c); + result += s; + return result; +} + +SkString operator+(const SkString& s1, const SkString& s2) { + SkString result(s1); + result += s2; + return result; +} + +bool operator==(const SkString& s1, const char* s2) { + return !strcmp(s1.c_str(), s2); +} + +bool operator!=(const SkString& s1, const char* s2) { + return strcmp(s1.c_str(), s2); +} + +bool operator!=(const char* s1, const SkString& s2) { + return strcmp(s1, s2.c_str()); +} } // namespace |