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 ConsumeDecimalNumber(Slice* in, uint64_t* val) {
51 while (!in->empty()) {
53 if (c >= '0' && c <= '9') {
55 const int delta = (c - '0');
56 static const uint64_t kMaxUint64 = ~static_cast<uint64_t>(0);
57 if (v > kMaxUint64/10 ||
58 (v == kMaxUint64/10 && delta > kMaxUint64%10)) {
72 } // namespace leveldb