blob: 430c802f4bb1419bdd9436cf816e930c35fc141e [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
Brian Osman31c075e2017-08-10 12:37:03 -04009#ifndef __STDC_FORMAT_MACROS
Brian Osman71a18892017-08-10 10:23:25 -040010#define __STDC_FORMAT_MACROS
Brian Osman31c075e2017-08-10 12:37:03 -040011#endif
12
Brian Osman71a18892017-08-10 10:23:25 -040013#include <inttypes.h>
14#include <stdarg.h>
15
16#include "SkJSONWriter.h"
17
18void SkJSONWriter::appendS64(int64_t value) {
19 this->beginValue();
20 this->appendf("%" PRId64, value);
21}
22
23void SkJSONWriter::appendU64(uint64_t value) {
24 this->beginValue();
25 this->appendf("%" PRIu64, value);
26}
27
28void SkJSONWriter::appendHexU64(uint64_t value) {
29 this->beginValue();
30 this->appendf("\"0x%" PRIx64 "\"", value);
31}
32
33void SkJSONWriter::appendf(const char* fmt, ...) {
34 const int kBufferSize = 1024;
35 char buffer[kBufferSize];
36 va_list argp;
37 va_start(argp, fmt);
38#ifdef SK_BUILD_FOR_WIN
39 int length = _vsnprintf_s(buffer, kBufferSize, _TRUNCATE, fmt, argp);
40#else
41 int length = vsnprintf(buffer, kBufferSize, fmt, argp);
42#endif
43 SkASSERT(length >= 0 && length < kBufferSize);
44 va_end(argp);
45 this->write(buffer, length);
46}