diff options
Diffstat (limited to 'gfx/skia/skia/src/utils/SkJSONWriter.cpp')
-rw-r--r-- | gfx/skia/skia/src/utils/SkJSONWriter.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gfx/skia/skia/src/utils/SkJSONWriter.cpp b/gfx/skia/skia/src/utils/SkJSONWriter.cpp new file mode 100644 index 0000000000..3038f2e7cf --- /dev/null +++ b/gfx/skia/skia/src/utils/SkJSONWriter.cpp @@ -0,0 +1,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); +} |