]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/util/string_util.h
bump version to 15.2.11-pve1
[ceph.git] / ceph / src / rocksdb / util / string_util.h
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
5 //
6
7 #pragma once
8
9 #include <sstream>
10 #include <string>
11 #include <unordered_map>
12 #include <vector>
13
14 namespace rocksdb {
15
16 class Slice;
17
18 extern std::vector<std::string> StringSplit(const std::string& arg, char delim);
19
20 template <typename T>
21 inline std::string ToString(T value) {
22 #if !(defined OS_ANDROID) && !(defined CYGWIN) && !(defined OS_FREEBSD)
23 return std::to_string(value);
24 #else
25 // Andorid or cygwin doesn't support all of C++11, std::to_string() being
26 // one of the not supported features.
27 std::ostringstream os;
28 os << value;
29 return os.str();
30 #endif
31 }
32
33 // Append a human-readable printout of "num" to *str
34 extern void AppendNumberTo(std::string* str, uint64_t num);
35
36 // Append a human-readable printout of "value" to *str.
37 // Escapes any non-printable characters found in "value".
38 extern void AppendEscapedStringTo(std::string* str, const Slice& value);
39
40 // Return a string printout of "num"
41 extern std::string NumberToString(uint64_t num);
42
43 // Return a human-readable version of num.
44 // for num >= 10.000, prints "xxK"
45 // for num >= 10.000.000, prints "xxM"
46 // for num >= 10.000.000.000, prints "xxG"
47 extern std::string NumberToHumanString(int64_t num);
48
49 // Return a human-readable version of bytes
50 // ex: 1048576 -> 1.00 GB
51 extern std::string BytesToHumanString(uint64_t bytes);
52
53 // Append a human-readable time in micros.
54 int AppendHumanMicros(uint64_t micros, char* output, int len,
55 bool fixed_format);
56
57 // Append a human-readable size in bytes
58 int AppendHumanBytes(uint64_t bytes, char* output, int len);
59
60 // Return a human-readable version of "value".
61 // Escapes any non-printable characters found in "value".
62 extern std::string EscapeString(const Slice& value);
63
64 // Parse a human-readable number from "*in" into *value. On success,
65 // advances "*in" past the consumed number and sets "*val" to the
66 // numeric value. Otherwise, returns false and leaves *in in an
67 // unspecified state.
68 extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val);
69
70 // Returns true if the input char "c" is considered as a special character
71 // that will be escaped when EscapeOptionString() is called.
72 //
73 // @param c the input char
74 // @return true if the input char "c" is considered as a special character.
75 // @see EscapeOptionString
76 bool isSpecialChar(const char c);
77
78 // If the input char is an escaped char, it will return the its
79 // associated raw-char. Otherwise, the function will simply return
80 // the original input char.
81 char UnescapeChar(const char c);
82
83 // If the input char is a control char, it will return the its
84 // associated escaped char. Otherwise, the function will simply return
85 // the original input char.
86 char EscapeChar(const char c);
87
88 // Converts a raw string to an escaped string. Escaped-characters are
89 // defined via the isSpecialChar() function. When a char in the input
90 // string "raw_string" is classified as a special characters, then it
91 // will be prefixed by '\' in the output.
92 //
93 // It's inverse function is UnescapeOptionString().
94 // @param raw_string the input string
95 // @return the '\' escaped string of the input "raw_string"
96 // @see isSpecialChar, UnescapeOptionString
97 std::string EscapeOptionString(const std::string& raw_string);
98
99 // The inverse function of EscapeOptionString. It converts
100 // an '\' escaped string back to a raw string.
101 //
102 // @param escaped_string the input '\' escaped string
103 // @return the raw string of the input "escaped_string"
104 std::string UnescapeOptionString(const std::string& escaped_string);
105
106 std::string trim(const std::string& str);
107
108 #ifndef ROCKSDB_LITE
109 bool ParseBoolean(const std::string& type, const std::string& value);
110
111 uint32_t ParseUint32(const std::string& value);
112
113 int32_t ParseInt32(const std::string& value);
114 #endif
115
116 uint64_t ParseUint64(const std::string& value);
117
118 int ParseInt(const std::string& value);
119
120
121 int64_t ParseInt64(const std::string& value);
122
123 double ParseDouble(const std::string& value);
124
125 size_t ParseSizeT(const std::string& value);
126
127 std::vector<int> ParseVectorInt(const std::string& value);
128
129 bool SerializeIntVector(const std::vector<int>& vec, std::string* value);
130
131 extern const std::string kNullptrString;
132
133 } // namespace rocksdb