2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2013-10-16 23:59:46 +02:00
|
|
|
//
|
2015-07-02 01:13:49 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-04-10 06:17:14 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2017-04-06 23:49:13 +02:00
|
|
|
#include <unordered_map>
|
2014-04-10 06:17:14 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2013-10-04 06:49:15 +02:00
|
|
|
namespace rocksdb {
|
2013-05-21 20:37:06 +02:00
|
|
|
|
2017-04-06 23:49:13 +02:00
|
|
|
class Slice;
|
|
|
|
|
2014-11-21 17:05:28 +01:00
|
|
|
extern std::vector<std::string> StringSplit(const std::string& arg, char delim);
|
2013-05-21 20:37:06 +02:00
|
|
|
|
2014-11-25 05:44:49 +01:00
|
|
|
template <typename T>
|
|
|
|
inline std::string ToString(T value) {
|
2016-06-29 16:35:17 +02:00
|
|
|
#if !(defined OS_ANDROID) && !(defined CYGWIN) && !(defined OS_FREEBSD)
|
2014-11-25 05:44:49 +01:00
|
|
|
return std::to_string(value);
|
|
|
|
#else
|
2015-04-24 04:17:57 +02:00
|
|
|
// Andorid or cygwin doesn't support all of C++11, std::to_string() being
|
2014-11-25 05:44:49 +01:00
|
|
|
// one of the not supported features.
|
|
|
|
std::ostringstream os;
|
|
|
|
os << value;
|
|
|
|
return os.str();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-04-06 23:49:13 +02:00
|
|
|
// Append a human-readable printout of "num" to *str
|
|
|
|
extern void AppendNumberTo(std::string* str, uint64_t num);
|
|
|
|
|
|
|
|
// Append a human-readable printout of "value" to *str.
|
|
|
|
// Escapes any non-printable characters found in "value".
|
|
|
|
extern void AppendEscapedStringTo(std::string* str, const Slice& value);
|
|
|
|
|
|
|
|
// Return a string printout of "num"
|
|
|
|
extern std::string NumberToString(uint64_t num);
|
|
|
|
|
|
|
|
// Return a human-readable version of num.
|
|
|
|
// for num >= 10.000, prints "xxK"
|
|
|
|
// for num >= 10.000.000, prints "xxM"
|
|
|
|
// for num >= 10.000.000.000, prints "xxG"
|
|
|
|
extern std::string NumberToHumanString(int64_t num);
|
|
|
|
|
|
|
|
// Return a human-readable version of bytes
|
|
|
|
// ex: 1048576 -> 1.00 GB
|
|
|
|
extern std::string BytesToHumanString(uint64_t bytes);
|
|
|
|
|
2019-07-04 04:03:29 +02:00
|
|
|
// Return a human-readable version of unix time
|
|
|
|
// ex: 1562116015 -> "Tue Jul 2 18:06:55 2019"
|
|
|
|
extern std::string TimeToHumanString(int unixtime);
|
|
|
|
|
2017-04-06 23:49:13 +02:00
|
|
|
// Append a human-readable time in micros.
|
|
|
|
int AppendHumanMicros(uint64_t micros, char* output, int len,
|
|
|
|
bool fixed_format);
|
|
|
|
|
|
|
|
// Append a human-readable size in bytes
|
|
|
|
int AppendHumanBytes(uint64_t bytes, char* output, int len);
|
|
|
|
|
|
|
|
// Return a human-readable version of "value".
|
|
|
|
// Escapes any non-printable characters found in "value".
|
|
|
|
extern std::string EscapeString(const Slice& value);
|
|
|
|
|
|
|
|
// Parse a human-readable number from "*in" into *value. On success,
|
|
|
|
// advances "*in" past the consumed number and sets "*val" to the
|
|
|
|
// numeric value. Otherwise, returns false and leaves *in in an
|
|
|
|
// unspecified state.
|
|
|
|
extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val);
|
|
|
|
|
|
|
|
// Returns true if the input char "c" is considered as a special character
|
|
|
|
// that will be escaped when EscapeOptionString() is called.
|
|
|
|
//
|
|
|
|
// @param c the input char
|
|
|
|
// @return true if the input char "c" is considered as a special character.
|
|
|
|
// @see EscapeOptionString
|
|
|
|
bool isSpecialChar(const char c);
|
|
|
|
|
|
|
|
// If the input char is an escaped char, it will return the its
|
|
|
|
// associated raw-char. Otherwise, the function will simply return
|
|
|
|
// the original input char.
|
|
|
|
char UnescapeChar(const char c);
|
|
|
|
|
|
|
|
// If the input char is a control char, it will return the its
|
|
|
|
// associated escaped char. Otherwise, the function will simply return
|
|
|
|
// the original input char.
|
|
|
|
char EscapeChar(const char c);
|
|
|
|
|
|
|
|
// Converts a raw string to an escaped string. Escaped-characters are
|
|
|
|
// defined via the isSpecialChar() function. When a char in the input
|
|
|
|
// string "raw_string" is classified as a special characters, then it
|
|
|
|
// will be prefixed by '\' in the output.
|
|
|
|
//
|
|
|
|
// It's inverse function is UnescapeOptionString().
|
|
|
|
// @param raw_string the input string
|
|
|
|
// @return the '\' escaped string of the input "raw_string"
|
|
|
|
// @see isSpecialChar, UnescapeOptionString
|
|
|
|
std::string EscapeOptionString(const std::string& raw_string);
|
|
|
|
|
|
|
|
// The inverse function of EscapeOptionString. It converts
|
|
|
|
// an '\' escaped string back to a raw string.
|
|
|
|
//
|
|
|
|
// @param escaped_string the input '\' escaped string
|
|
|
|
// @return the raw string of the input "escaped_string"
|
|
|
|
std::string UnescapeOptionString(const std::string& escaped_string);
|
|
|
|
|
|
|
|
std::string trim(const std::string& str);
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
bool ParseBoolean(const std::string& type, const std::string& value);
|
|
|
|
|
|
|
|
uint32_t ParseUint32(const std::string& value);
|
2019-03-12 21:46:12 +01:00
|
|
|
|
|
|
|
int32_t ParseInt32(const std::string& value);
|
2017-04-06 23:49:13 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
uint64_t ParseUint64(const std::string& value);
|
|
|
|
|
|
|
|
int ParseInt(const std::string& value);
|
|
|
|
|
2019-03-12 21:46:12 +01:00
|
|
|
|
|
|
|
int64_t ParseInt64(const std::string& value);
|
|
|
|
|
2017-04-06 23:49:13 +02:00
|
|
|
double ParseDouble(const std::string& value);
|
|
|
|
|
|
|
|
size_t ParseSizeT(const std::string& value);
|
|
|
|
|
|
|
|
std::vector<int> ParseVectorInt(const std::string& value);
|
|
|
|
|
|
|
|
bool SerializeIntVector(const std::vector<int>& vec, std::string* value);
|
|
|
|
|
|
|
|
extern const std::string kNullptrString;
|
|
|
|
|
2014-04-10 06:17:14 +02:00
|
|
|
} // namespace rocksdb
|