blob: 3b92aa4576b74f2f180a31feddcb8c5a83f57558 [file] [log] [blame]
Brian Osman71a18892017-08-10 10:23:25 -04001/*
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// Make sure that the PRI format string macros are defined
9#define __STDC_FORMAT_MACROS
10#include <inttypes.h>
11#include <stdarg.h>
12
13#include "SkJSONWriter.h"
14
15void SkJSONWriter::appendS64(int64_t value) {
16 this->beginValue();
17 this->appendf("%" PRId64, value);
18}
19
20void SkJSONWriter::appendU64(uint64_t value) {
21 this->beginValue();
22 this->appendf("%" PRIu64, value);
23}
24
25void SkJSONWriter::appendHexU64(uint64_t value) {
26 this->beginValue();
27 this->appendf("\"0x%" PRIx64 "\"", value);
28}
29
30void SkJSONWriter::appendf(const char* fmt, ...) {
31 const int kBufferSize = 1024;
32 char buffer[kBufferSize];
33 va_list argp;
34 va_start(argp, fmt);
35#ifdef SK_BUILD_FOR_WIN
36 int length = _vsnprintf_s(buffer, kBufferSize, _TRUNCATE, fmt, argp);
37#else
38 int length = vsnprintf(buffer, kBufferSize, fmt, argp);
39#endif
40 SkASSERT(length >= 0 && length < kBufferSize);
41 va_end(argp);
42 this->write(buffer, length);
43}