aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLUtil.cpp
blob: 2b51cffcd6d81ee6f874d72c833e262ddc2e4848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkSLUtil.h"

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) {
        result += ".0";
    }
    return result;
}

std::string to_string(int32_t value) {
    std::stringstream buffer;
    buffer << value;
    return buffer.str();
}

std::string to_string(uint32_t value) {
    std::stringstream buffer;
    buffer << value;
    return buffer.str();
}

std::string to_string(int64_t value) {
    std::stringstream buffer;
    buffer << value;
    return buffer.str();
}

std::string to_string(uint64_t value) {
    std::stringstream buffer;
    buffer << value;
    return buffer.str();
}

int stoi(std::string s) {
    if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
        char* p;
        int result = strtoul(s.substr(2).c_str(), &p, 16);
        ASSERT(*p == 0);
        return result;
    }
    return atoi(s.c_str());
}

double stod(std::string s) {
    return atof(s.c_str());
}

long stol(std::string s) {
    if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
        char* p;
        int result = strtoul(s.substr(2).c_str(), &p, 16);
        ASSERT(*p == 0);
        return result;
    }
    return atol(s.c_str());
}

void sksl_abort() {
#ifdef SKIA
    sk_abort_no_print();
    exit(1);
#else
    abort();
#endif
}

} // namespace