MCPcopy Create free account
hub / github.com/baidu/BaikalDB / String

Class String

include/sqlparser/utils.h:42–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41namespace parser {
42struct String {
43 char* value;
44 size_t length;
45 void strdup(const char* str, int len, butil::Arena& arena) {
46 value = (char*)arena.allocate(len + 1);
47 length = len;
48 memcpy(value, str, len);
49 value[len] = '\0';
50 }
51 void strdup(const char* str, butil::Arena& arena) {
52 strdup(str, strlen(str), arena);
53 }
54 void append(const char* str, butil::Arena& arena) {
55 int len = strlen(str);
56 int old_len = length;
57 length += len;
58 char* value_new = (char*)arena.allocate(length + 1);
59 memcpy(value_new, value, old_len);
60 memcpy(value_new + old_len, str, len);
61 value_new[length] = '\0';
62 value = value_new;
63 }
64 // cannot have constructor in union
65 void set_null() {
66 value = nullptr;
67 length = 0;
68 }
69 const char* c_str() const {
70 return value;
71 }
72 std::string to_string() const {
73 return std::string(value, length);
74 }
75 bool empty() const {
76 return (length == 0 || value == nullptr || value[0] == '\0');
77 }
78 void restore_5c() {
79 size_t i = 0;
80 while (i < length) {
81 if ((value[i] & 0x80) != 0) {
82 if (++i >= length) {
83 return;
84 }
85 if (value[i] == 0x7F) {
86 value[i] = 0x5C;
87 }
88 }
89 ++i;
90 }
91 }
92 void stripslashes(char c) {
93 size_t slow = 0;
94 size_t fast = 0;
95 bool has_slash = false;
96 static std::unordered_map<char, char> trans_map = {
97 {'0', '\x00'},
98 {'\\', '\\'},
99 {'\"', '\"'},

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected