1
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file. See the AUTHORS file for names of contributors.
5
#include "util/logging.h"
11
#include "leveldb/env.h"
12
#include "leveldb/slice.h"
16
void AppendNumberTo(std::string* str, uint64_t num) {
18
snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num);
22
void AppendEscapedStringTo(std::string* str, const Slice& value) {
23
for (size_t i = 0; i < value.size(); i++) {
25
if (c >= ' ' && c <= '~') {
29
snprintf(buf, sizeof(buf), "\\x%02x",
30
static_cast<unsigned int>(c) & 0xff);
36
std::string NumberToString(uint64_t num) {
38
AppendNumberTo(&r, num);
42
std::string EscapeString(const Slice& value) {
44
AppendEscapedStringTo(&r, value);
48
bool ConsumeChar(Slice* in, char c) {
49
if (!in->empty() && (*in)[0] == c) {
57
bool ConsumeDecimalNumber(Slice* in, uint64_t* val) {
60
while (!in->empty()) {
62
if (c >= '0' && c <= '9') {
64
const int delta = (c - '0');
65
static const uint64_t kMaxUint64 = ~static_cast<uint64_t>(0);
66
if (v > kMaxUint64/10 ||
67
(v == kMaxUint64/10 && delta > kMaxUint64%10)) {
81
} // namespace leveldb