Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions
SkSLString.cpp File Reference
#include "src/base/SkStringView.h"
#include "src/sksl/SkSLDefines.h"
#include "src/sksl/SkSLString.h"
#include <cerrno>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <locale>
#include <memory>
#include <sstream>
#include <string>
#include <string_view>

Go to the source code of this file.

Macros

#define BUFFER_SIZE   256
 

Functions

template<typename RoundtripType , int kFullPrecision>
static std::string to_string_impl (RoundtripType value)
 

Macro Definition Documentation

◆ BUFFER_SIZE

#define BUFFER_SIZE   256

Function Documentation

◆ to_string_impl()

template<typename RoundtripType , int kFullPrecision>
static std::string to_string_impl ( RoundtripType  value)
static

Definition at line 23 of file SkSLString.cpp.

23 {
24 std::stringstream buffer;
25 buffer.imbue(std::locale::classic());
26 buffer.precision(7);
27 buffer << value;
28 std::string text = buffer.str();
29
30 double roundtripped;
31 buffer >> roundtripped;
32 if (value != (RoundtripType)roundtripped && std::isfinite(value)) {
33 buffer.str({});
34 buffer.clear();
35 buffer.precision(kFullPrecision);
36 buffer << value;
37 text = buffer.str();
38 SkASSERTF((buffer >> roundtripped, value == (RoundtripType)roundtripped),
39 "%.17g -> %s -> %.17g", value, text.c_str(), roundtripped);
40 }
41
42 // We need to emit a decimal point to distinguish floats from ints.
43 if (!skstd::contains(text, '.') && !skstd::contains(text, 'e')) {
44 text += ".0";
45 }
46
47 return text;
48}
#define SkASSERTF(cond, fmt,...)
Definition SkAssert.h:117
static const uint8_t buffer[]
uint8_t value
std::u16string text
constexpr bool contains(std::string_view str, std::string_view needle)