OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkSLUtil.h" | 8 #include "SkSLUtil.h" |
9 | 9 |
10 namespace SkSL { | 10 namespace SkSL { |
11 | 11 |
| 12 std::string to_string(double value) { |
| 13 std::stringstream buffer; |
| 14 buffer << std::setprecision(std::numeric_limits<double>::digits10) << value; |
| 15 std::string result = buffer.str(); |
| 16 if (result.find_last_of(".") == std::string::npos && |
| 17 result.find_last_of("e") == std::string::npos) { |
| 18 result += ".0"; |
| 19 } |
| 20 return result; |
| 21 } |
| 22 |
| 23 std::string to_string(int32_t value) { |
| 24 std::stringstream buffer; |
| 25 buffer << value; |
| 26 return buffer.str(); |
| 27 } |
| 28 |
| 29 std::string to_string(uint32_t value) { |
| 30 std::stringstream buffer; |
| 31 buffer << value; |
| 32 return buffer.str(); |
| 33 } |
| 34 |
| 35 std::string to_string(int64_t value) { |
| 36 std::stringstream buffer; |
| 37 buffer << value; |
| 38 return buffer.str(); |
| 39 } |
| 40 |
| 41 std::string to_string(uint64_t value) { |
| 42 std::stringstream buffer; |
| 43 buffer << value; |
| 44 return buffer.str(); |
| 45 } |
| 46 |
12 int stoi(std::string s) { | 47 int stoi(std::string s) { |
13 return atoi(s.c_str()); | 48 return atoi(s.c_str()); |
14 } | 49 } |
15 | 50 |
16 double stod(std::string s) { | 51 double stod(std::string s) { |
17 return atof(s.c_str()); | 52 return atof(s.c_str()); |
18 } | 53 } |
19 | 54 |
20 long stol(std::string s) { | 55 long stol(std::string s) { |
21 return atol(s.c_str()); | 56 return atol(s.c_str()); |
22 } | 57 } |
23 | 58 |
24 void sksl_abort() { | 59 void sksl_abort() { |
25 #ifdef SKIA | 60 #ifdef SKIA |
26 sk_abort_no_print(); | 61 sk_abort_no_print(); |
27 exit(1); | 62 exit(1); |
28 #else | 63 #else |
29 abort(); | 64 abort(); |
30 #endif | 65 #endif |
31 } | 66 } |
32 | 67 |
33 } // namespace | 68 } // namespace |
OLD | NEW |