blob: 3038f2e7cf38682d72604aeed5e7de6ae253b1dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// Make sure that the PRI format string macros are defined
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include "src/utils/SkJSONWriter.h"
#include <inttypes.h>
#include <stdarg.h>
#include <stdio.h>
void SkJSONWriter::appendS64(int64_t value) {
this->beginValue();
this->appendf("%" PRId64, value);
}
void SkJSONWriter::appendU64(uint64_t value) {
this->beginValue();
this->appendf("%" PRIu64, value);
}
void SkJSONWriter::appendHexU64(uint64_t value) {
this->beginValue();
this->appendf("\"0x%" PRIx64 "\"", value);
}
void SkJSONWriter::appendf(const char* fmt, ...) {
const int kBufferSize = 1024;
char buffer[kBufferSize];
va_list argp;
va_start(argp, fmt);
#ifdef SK_BUILD_FOR_WIN
int length = _vsnprintf_s(buffer, kBufferSize, _TRUNCATE, fmt, argp);
#else
int length = vsnprintf(buffer, kBufferSize, fmt, argp);
#endif
SkASSERT(length >= 0 && length < kBufferSize);
va_end(argp);
this->write(buffer, length);
}
|