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
8#include "src/sksl/SkSLOutputStream.h"
9
10#include <memory>
11
12namespace SkSL {
13
14void OutputStream::writeString(String s) {
15 this->write(s.c_str(), s.size());
16}
17
18void OutputStream::printf(const char format[], ...) {
19 va_list args;
20 va_start(args, format);
21 this->appendVAList(format, args);
22 va_end(args);
23}
24
25void OutputStream::appendVAList(const char format[], va_list args) {
26 char buffer[kBufferSize];
27 va_list copy;
28 va_copy(copy, args);
29 int length = vsnprintf(buffer, kBufferSize, format, args);
30 if (length > (int) kBufferSize) {
31 std::unique_ptr<char[]> bigBuffer(new char[length + 1]);
32 vsnprintf(bigBuffer.get(), length + 1, format, copy);
33 this->write(bigBuffer.get(), length);
34 } else {
35 this->write(buffer, length);
36 }
37 va_end(copy);
38}
39
40} // namespace SkSL
41