Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLString.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 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 SKSL_STRING
9#define SKSL_STRING
10
14
15#include <stdarg.h>
16#include <string>
17#include <string_view>
18
19namespace SkSL {
20
21bool stod(std::string_view s, SKSL_FLOAT* value);
22bool stoi(std::string_view s, SKSL_INT* value);
23
24namespace String {
25
26std::string printf(const char* fmt, ...) SK_PRINTF_LIKE(1, 2);
27void appendf(std::string* str, const char* fmt, ...) SK_PRINTF_LIKE(2, 3);
28void vappendf(std::string* str, const char* fmt, va_list va) SK_PRINTF_LIKE(2, 0);
29
30inline auto Separator() {
31 // This returns a lambda which emits "" the first time it is called, and ", " every subsequent
32 // time it is called.
33 struct Output {
34 const std::string fSpace, fComma;
35 };
36 static const SkNoDestructor<Output> kOutput(Output{{}, {", "}});
37
38 return [firstSeparator = true]() mutable -> const std::string& {
39 if (firstSeparator) {
40 firstSeparator = false;
41 return kOutput->fSpace;
42 } else {
43 return kOutput->fComma;
44 }
45 };
46}
47
48} // namespace String
49} // namespace SkSL
50
51namespace skstd {
52
53// We use a custom to_string(float|double) which ignores locale settings and writes `1.0` instead
54// of `1.00000`.
55std::string to_string(float value);
56std::string to_string(double value);
57
58} // namespace skstd
59
60#endif
#define SK_PRINTF_LIKE(A, B)
Output
Definition SkSLBench.cpp:61
int64_t SKSL_INT
Definition SkSLDefines.h:16
float SKSL_FLOAT
Definition SkSLDefines.h:17
struct MyStruct s
std::string void void vappendf(std::string *str, const char *fmt, va_list va) SK_PRINTF_LIKE(2
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
std::string void void auto Separator()
Definition SkSLString.h:30
std::string void appendf(std::string *str, const char *fmt,...) SK_PRINTF_LIKE(2
bool stod(std::string_view s, SKSL_FLOAT *value)
bool stoi(std::string_view s, SKSL_INT *value)
std::string to_string(float value)
static SkString fmt(SkColor4f c)
Definition p3.cpp:43