mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-29 20:47:31 -03:00
b13a68e129
c521b3ac6 Merge #11: fixup define checks. Cleans up some oopses from #5. 8b1cd3753 fixup define checks. Cleans up some oopses from #5. 6b1508d6d Merge #6: Fixes typo fceb80542 Merge #10: Clean up compile-time warnings (gcc 7.1) 0ec2a343f Clean up compile-time warnings (gcc 7.1) d4c268a35 Merge #5: Move helper functions out of sse4.2 object 8d4eb0847 Add HasAcceleratedCRC32C to port_win.h 77cfbfd25 crc32: move helper functions out of port_posix_sse.cc 4c1e9e016 silence compiler warnings about uninitialized variables 495316485 Merge #2: Prefer std::atomic over MemoryBarrier 2953978ef Fixes typo f134284a1 Merge #1: Merge upstream LevelDB 1.20 ba8a445fd Prefer std::atomic over MemoryBarrier git-subtree-dir: src/leveldb git-subtree-split: c521b3ac654cfbe009c575eacf7e5a6e189bb5bb
72 lines
1.7 KiB
C++
72 lines
1.7 KiB
C++
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#include "util/logging.h"
|
|
|
|
#include <errno.h>
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "leveldb/env.h"
|
|
#include "leveldb/slice.h"
|
|
|
|
namespace leveldb {
|
|
|
|
void AppendNumberTo(std::string* str, uint64_t num) {
|
|
char buf[30];
|
|
snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num);
|
|
str->append(buf);
|
|
}
|
|
|
|
void AppendEscapedStringTo(std::string* str, const Slice& value) {
|
|
for (size_t i = 0; i < value.size(); i++) {
|
|
char c = value[i];
|
|
if (c >= ' ' && c <= '~') {
|
|
str->push_back(c);
|
|
} else {
|
|
char buf[10];
|
|
snprintf(buf, sizeof(buf), "\\x%02x",
|
|
static_cast<unsigned int>(c) & 0xff);
|
|
str->append(buf);
|
|
}
|
|
}
|
|
}
|
|
|
|
std::string NumberToString(uint64_t num) {
|
|
std::string r;
|
|
AppendNumberTo(&r, num);
|
|
return r;
|
|
}
|
|
|
|
std::string EscapeString(const Slice& value) {
|
|
std::string r;
|
|
AppendEscapedStringTo(&r, value);
|
|
return r;
|
|
}
|
|
|
|
bool ConsumeDecimalNumber(Slice* in, uint64_t* val) {
|
|
uint64_t v = 0;
|
|
int digits = 0;
|
|
while (!in->empty()) {
|
|
unsigned char c = (*in)[0];
|
|
if (c >= '0' && c <= '9') {
|
|
++digits;
|
|
const int delta = (c - '0');
|
|
static const uint64_t kMaxUint64 = ~static_cast<uint64_t>(0);
|
|
if (v > kMaxUint64/10 ||
|
|
(v == kMaxUint64/10 && delta > kMaxUint64%10)) {
|
|
// Overflow
|
|
return false;
|
|
}
|
|
v = (v * 10) + delta;
|
|
in->remove_prefix(1);
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
*val = v;
|
|
return (digits > 0);
|
|
}
|
|
|
|
} // namespace leveldb
|