Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLOutputStream.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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
9
10#include <stdio.h>
11#include <memory>
12
13namespace SkSL {
14
15void OutputStream::writeString(const std::string& s) {
16 this->write(s.c_str(), s.size());
17}
18
19void OutputStream::printf(const char format[], ...) {
20 va_list args;
21 va_start(args, format);
22 this->appendVAList(format, args);
23 va_end(args);
24}
25
26void OutputStream::appendVAList(const char format[], va_list args) {
27 char buffer[kBufferSize];
28 va_list copy;
29 va_copy(copy, args);
30 int length = vsnprintf(buffer, kBufferSize, format, args);
31 if (length > (int) kBufferSize) {
32 std::unique_ptr<char[]> bigBuffer(new char[length + 1]);
33 vsnprintf(bigBuffer.get(), length + 1, format, copy);
34 this->write(bigBuffer.get(), length);
35 } else {
36 this->write(buffer, length);
37 }
38 va_end(copy);
39}
40
41} // namespace SkSL
void writeString(const std::string &s)
virtual void write(const void *s, size_t size)=0
void printf(const char format[],...) SK_PRINTF_LIKE(2
void void appendVAList(const char format[], va_list args) SK_PRINTF_LIKE(2
struct MyStruct s
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
static const uint8_t buffer[]
uint32_t uint32_t * format
size_t length
Definition copy.py:1