| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#ifndef RTC_BASE_STRING_ENCODE_H_ |
| 12 |
#define RTC_BASE_STRING_ENCODE_H_ |
| 13 |
|
| 14 |
#include <stddef.h> |
| 15 |
|
| 16 |
#include <string> |
| 17 |
#include <type_traits> |
| 18 |
#include <vector> |
| 19 |
|
| 20 |
#include "absl/types/optional.h" |
| 21 |
#include "rtc_base/checks.h" |
| 22 |
#include "rtc_base/string_to_number.h" |
| 23 |
|
| 24 |
namespace rtc { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
std::string hex_encode(const std::string& str); |
| 31 |
std::string hex_encode(const char* source, size_t srclen); |
| 32 |
std::string hex_encode_with_delimiter(const char* source, |
| 33 |
size_t srclen, |
| 34 |
char delimiter); |
| 35 |
|
| 36 |
|
| 37 |
size_t hex_decode(char* buffer, |
| 38 |
size_t buflen, |
| 39 |
const char* source, |
| 40 |
size_t srclen); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
size_t hex_decode_with_delimiter(char* buffer, |
| 47 |
size_t buflen, |
| 48 |
const char* source, |
| 49 |
size_t srclen, |
| 50 |
char delimiter); |
| 51 |
|
| 52 |
|
| 53 |
size_t hex_decode(char* buffer, size_t buflen, const std::string& source); |
| 54 |
size_t hex_decode_with_delimiter(char* buffer, |
| 55 |
size_t buflen, |
| 56 |
const std::string& source, |
| 57 |
char delimiter); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
std::string join(const std::vector<std::string>& source, char delimiter); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
size_t split(const std::string& source, |
| 66 |
char delimiter, |
| 67 |
std::vector<std::string>* fields); |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
size_t tokenize(const std::string& source, |
| 72 |
char delimiter, |
| 73 |
std::vector<std::string>* fields); |
| 74 |
|
| 75 |
|
| 76 |
size_t tokenize_with_empty_tokens(const std::string& source, |
| 77 |
char delimiter, |
| 78 |
std::vector<std::string>* fields); |
| 79 |
|
| 80 |
|
| 81 |
size_t tokenize_append(const std::string& source, |
| 82 |
char delimiter, |
| 83 |
std::vector<std::string>* fields); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
size_t tokenize(const std::string& source, |
| 93 |
char delimiter, |
| 94 |
char start_mark, |
| 95 |
char end_mark, |
| 96 |
std::vector<std::string>* fields); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
bool tokenize_first(const std::string& source, |
| 102 |
const char delimiter, |
| 103 |
std::string* token, |
| 104 |
std::string* rest); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
std::string ToString(bool b); |
| 109 |
|
| 110 |
std::string ToString(const char* s); |
| 111 |
std::string ToString(std::string t); |
| 112 |
|
| 113 |
std::string ToString(short s); |
| 114 |
std::string ToString(unsigned short s); |
| 115 |
std::string ToString(int s); |
| 116 |
std::string ToString(unsigned int s); |
| 117 |
std::string ToString(long int s); |
| 118 |
std::string ToString(unsigned long int s); |
| 119 |
std::string ToString(long long int s); |
| 120 |
std::string ToString(unsigned long long int s); |
| 121 |
|
| 122 |
std::string ToString(double t); |
| 123 |
std::string ToString(long double t); |
| 124 |
|
| 125 |
std::string ToString(const void* p); |
| 126 |
|
| 127 |
template <typename T, |
| 128 |
typename std::enable_if<std::is_arithmetic<T>::value && |
| 129 |
!std::is_same<T, bool>::value, |
| 130 |
int>::type = 0> |
| 131 |
static bool FromString(const std::string& s, T* t) { |
| 132 |
RTC_DCHECK(t); |
| 133 |
absl::optional<T> result = StringToNumber<T>(s); |
| 134 |
|
| 135 |
if (result) |
| 136 |
*t = *result; |
| 137 |
|
| 138 |
return result.has_value(); |
| 139 |
} |
| 140 |
|
| 141 |
bool FromString(const std::string& s, bool* b); |
| 142 |
|
| 143 |
template <typename T> |
| 144 |
static inline T FromString(const std::string& str) { |
| 145 |
T val; |
| 146 |
FromString(str, &val); |
| 147 |
return val; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
} |
| 153 |
|
| 154 |
#endif |