MySQL 8.0.29
Source Code Documentation
sql_string.h
Go to the documentation of this file.
1#ifndef SQL_STRING_INCLUDED
2#define SQL_STRING_INCLUDED
3
4/* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file include/sql_string.h
28 Our own string classes, used pervasively throughout the executor.
29 See in particular the comment on String before you use anything from here.
30*/
31
32#include <assert.h>
33#include <stdint.h>
34#include <string.h>
35#include <sys/types.h>
36#include <new>
37#include <string>
38#include <string_view>
39
40#include "lex_string.h"
41#include "m_ctype.h" // my_convert
42#include "m_string.h" // LEX_CSTRING
43#include "memory_debugging.h"
44#include "my_alloc.h"
45#include "my_compiler.h"
46
47#include "my_inttypes.h"
49#include "mysql/mysql_lex_string.h" // LEX_STRING
51#include "mysql/service_mysql_alloc.h" // my_free
52
53struct MEM_ROOT;
54
55#ifdef MYSQL_SERVER
57#define STRING_PSI_MEMORY_KEY key_memory_String_value
58#else
59#define STRING_PSI_MEMORY_KEY PSI_NOT_INSTRUMENTED
60#endif
61
62/**
63 A wrapper class for null-terminated constant strings.
64 Constructors make sure that the position of the '\0' terminating byte
65 in m_str is always in sync with m_length.
66
67 This class must stay as small as possible as we often
68 pass it and its descendants (such as Name_string) into functions
69 using call-by-value evaluation.
70
71 Don't add new members or virual methods into this class!
72*/
74 private:
75 const char *m_str;
76 size_t m_length;
77
78 public:
79 /**
80 Initialize from a C string whose length is already known.
81 */
82 void set(const char *str_arg, size_t length_arg) {
83 // NULL is allowed only with length==0
84 assert(str_arg || length_arg == 0);
85 // For non-NULL, make sure length_arg is in sync with '\0' terminator.
86 assert(!str_arg || str_arg[length_arg] == '\0');
87 m_str = str_arg;
88 m_length = length_arg;
89 }
90 Simple_cstring() { set(nullptr, 0); }
91 Simple_cstring(const char *str_arg, size_t length_arg) {
92 set(str_arg, length_arg);
93 }
94 Simple_cstring(const LEX_STRING arg) { set(arg.str, arg.length); }
95 Simple_cstring(const LEX_CSTRING arg) { set(arg.str, arg.length); }
96 void reset() { set(nullptr, 0); }
97 /**
98 Set to a null-terminated string.
99 */
100 void set(const char *str) { set(str, str ? strlen(str) : 0); }
101 /**
102 Return string buffer.
103 */
104 const char *ptr() const { return m_str; }
105 /**
106 Check if m_ptr is set.
107 */
108 bool is_set() const { return m_str != nullptr; }
109 /**
110 Return name length.
111 */
112 size_t length() const { return m_length; }
113 /**
114 Compare to another Simple_cstring.
115 */
116 bool eq_bin(const Simple_cstring other) const {
117 return m_length == other.m_length &&
118 memcmp(m_str, other.m_str, m_length) == 0;
119 }
120 /**
121 Copy to the given buffer
122 */
123 void strcpy(char *buff) const {
124 memcpy(buff, m_str, m_length);
125 buff[m_length] = '\0';
126 }
127};
128
129class String;
130
131struct CHARSET_INFO;
132struct IO_CACHE;
133
134bool validate_string(const CHARSET_INFO *cs, const char *str, size_t length,
135 size_t *valid_length, bool *length_error);
136int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs);
137String *copy_if_not_alloced(String *to, String *from, size_t from_length);
138inline size_t copy_and_convert(char *to, size_t to_length,
139 const CHARSET_INFO *to_cs, const char *from,
140 size_t from_length, const CHARSET_INFO *from_cs,
141 uint *errors) {
142 return my_convert(to, to_length, to_cs, from, from_length, from_cs, errors);
143}
144size_t well_formed_copy_nchars(const CHARSET_INFO *to_cs, char *to,
145 size_t to_length, const CHARSET_INFO *from_cs,
146 const char *from, size_t from_length,
147 size_t nchars,
148 const char **well_formed_error_pos,
149 const char **cannot_convert_error_pos,
150 const char **from_end_pos);
151size_t convert_to_printable(char *to, size_t to_len, const char *from,
152 size_t from_len, const CHARSET_INFO *from_cs,
153 size_t nbytes = 0);
154
155size_t bin_to_hex_str(char *to, size_t to_len, const char *from,
156 size_t from_len);
157
158/**
159 Using this class is fraught with peril, and you need to be very careful
160 when doing so. In particular, copy construction and assignment does not
161 do a deep _nor_ a shallow copy; instead, it makes a _reference_ to the
162 original string that will be invalid as soon as that string goes out of scope.
163 (Move constructiong and assignment is safe, though.) In general, it is
164 probably better not to use this class at all if you can avoid it.
165*/
166class String {
167 char *m_ptr;
168 size_t m_length;
170 uint32
171 m_alloced_length; // should be size_t, but kept uint32 for size reasons
173
174 public:
176 : m_ptr(nullptr),
177 m_length(0),
180 m_is_alloced(false) {}
181 explicit String(size_t length_arg)
182 : m_ptr(nullptr),
183 m_length(0),
186 m_is_alloced(false) {
187 (void)real_alloc(length_arg);
188 }
189 String(const char *str, const CHARSET_INFO *cs)
190 : m_ptr(const_cast<char *>(str)),
191 m_length(strlen(str)),
192 m_charset(cs),
194 m_is_alloced(false) {}
195 String(const char *str, size_t len, const CHARSET_INFO *cs)
196 : m_ptr(const_cast<char *>(str)),
197 m_length(len),
198 m_charset(cs),
200 m_is_alloced(false) {}
201 String(char *str, size_t len, const CHARSET_INFO *cs)
202 : m_ptr(str),
203 m_length(len),
204 m_charset(cs),
205 m_alloced_length(static_cast<uint32>(len)),
206 m_is_alloced(false) {}
208 : m_ptr(str.m_ptr),
212 m_is_alloced(false) {}
213 String(String &&str) noexcept
214 : m_ptr(str.m_ptr),
215 m_length(str.m_length),
216 m_charset(str.m_charset),
217 m_alloced_length(str.m_alloced_length),
218 m_is_alloced(str.m_is_alloced) {
219 str.m_is_alloced = false;
220 }
221 static void *operator new(size_t size, MEM_ROOT *mem_root,
222 const std::nothrow_t &arg
223 [[maybe_unused]] = std::nothrow) noexcept {
224 return mem_root->Alloc(size);
225 }
226 static void operator delete(void *ptr_arg, size_t size) {
227 (void)ptr_arg;
228 (void)size;
229 TRASH(ptr_arg, size);
230 }
231
232 static void operator delete(
233 void *, MEM_ROOT *, const std::nothrow_t &) noexcept { /* never called */
234 }
235
237
238 void set_charset(const CHARSET_INFO *charset_arg) { m_charset = charset_arg; }
239 const CHARSET_INFO *charset() const { return m_charset; }
240 size_t length() const { return m_length; }
241 size_t alloced_length() const { return m_alloced_length; }
242 const char &operator[](size_t i) const { return m_ptr[i]; }
243 char &operator[](size_t i) { return m_ptr[i]; }
244 void length(size_t len) { m_length = len; }
245 bool is_empty() const { return (m_length == 0); }
247 /* Returns a pointer to data, may not include NULL terminating character. */
248 const char *ptr() const { return m_ptr; }
249 char *ptr() { return m_ptr; }
250 char *c_ptr() {
251 assert(!m_is_alloced || !m_ptr || !m_alloced_length ||
252 (m_alloced_length >= (m_length + 1)));
253
254 /*
255 Should be safe, but in case valgrind complains on this line, it means
256 there is a misuse of c_ptr(). Please prefer <ptr(), length()> instead.
257 */
258 if (!m_ptr || m_ptr[m_length]) (void)mem_realloc(m_length);
259 return m_ptr;
260 }
261 char *c_ptr_quick() {
263 return m_ptr;
264 }
265 char *c_ptr_safe() {
267 m_ptr[m_length] = 0;
268 else
269 (void)mem_realloc(m_length);
270 return m_ptr;
271 }
273
276 return lex_cstring;
277 }
278
279 void set(String &str, size_t offset, size_t arg_length) {
280 assert(&str != this);
281 mem_free();
282 m_ptr = str.ptr() + offset;
283 m_length = arg_length;
284 m_is_alloced = false;
285 if (str.m_alloced_length)
286 m_alloced_length = str.m_alloced_length - static_cast<uint32>(offset);
287 else
289 m_charset = str.m_charset;
290 }
291
292 /**
293 Points the internal buffer to the supplied one. The old buffer is freed.
294 @param str Pointer to the new buffer.
295 @param arg_length Length of the new buffer in characters, excluding any
296 null character.
297 @param cs Character set to use for interpreting string data.
298 @note The new buffer will not be null terminated.
299 */
300 void set(char *str, size_t arg_length, const CHARSET_INFO *cs) {
301 mem_free();
302 m_ptr = str;
303 m_length = m_alloced_length = static_cast<uint32>(arg_length);
304 m_is_alloced = false;
305 m_charset = cs;
306 }
307 void set(const char *str, size_t arg_length, const CHARSET_INFO *cs) {
308 mem_free();
309 m_ptr = const_cast<char *>(str);
310 m_length = arg_length;
312 m_is_alloced = false;
313 m_charset = cs;
314 }
315 bool set_ascii(const char *str, size_t arg_length);
316 void set_quick(char *str, size_t arg_length, const CHARSET_INFO *cs) {
317 if (!m_is_alloced) {
318 m_ptr = str;
319 m_length = arg_length;
320 m_alloced_length = static_cast<uint32>(arg_length);
321 }
322 m_charset = cs;
323 }
324 bool set_int(longlong num, bool unsigned_flag, const CHARSET_INFO *cs);
325 bool set(longlong num, const CHARSET_INFO *cs) {
326 return set_int(num, false, cs);
327 }
328 bool set(ulonglong num, const CHARSET_INFO *cs) {
329 return set_int((longlong)num, true, cs);
330 }
331
332 /**
333 Sets the contents of this string to the string representation of the given
334 double value.
335
336 @param num the double value
337 @param decimals the number of decimals
338 @param cs the character set of the string
339 @return false on success, true on error
340 */
341 bool set_real(double num, uint decimals, const CHARSET_INFO *cs);
342
343 /*
344 PMG 2004.11.12
345 This is a method that works the same as perl's "chop". It simply
346 drops the last byte of a string. This is useful in the case
347 of the federated storage handler where I'm building a unknown
348 number, list of values and fields to be used in a sql insert
349 statement to be run on the remote server, and have a comma after each.
350 When the list is complete, I "chop" off the trailing comma
351
352 ex.
353 String stringobj;
354 stringobj.append("VALUES ('foo', 'fi', 'fo',");
355 stringobj.chop();
356 stringobj.append(")");
357
358 In this case, the value of string was:
359
360 VALUES ('foo', 'fi', 'fo',
361 VALUES ('foo', 'fi', 'fo'
362 VALUES ('foo', 'fi', 'fo')
363
364 This is not safe to call when the string ends in a multi-byte character!
365 */
366 void chop() {
367 m_length--;
368 m_ptr[m_length] = '\0';
369 }
370
371 void mem_claim(bool claim) {
372 if (m_is_alloced) {
373 my_claim(m_ptr, claim);
374 }
375 }
376
377 void mem_free() {
378 if (m_is_alloced) {
379 m_is_alloced = false;
381 my_free(m_ptr);
382 m_ptr = nullptr;
383 m_length = 0; /* Safety */
384 }
385 }
386
387 bool alloc(size_t arg_length) {
388 if (arg_length < m_alloced_length) return false;
389 return real_alloc(arg_length);
390 }
391 bool real_alloc(size_t arg_length); // Empties old string
392 bool mem_realloc(size_t arg_length, bool force_on_heap = false);
393
394 private:
395 size_t next_realloc_exp_size(size_t sz);
396 bool mem_realloc_exp(size_t arg_length);
397
398 public:
399 // Shrink the buffer, but only if it is allocated on the heap.
400 void shrink(size_t arg_length) {
401 if (!is_alloced()) return;
402 if (arg_length < m_alloced_length) {
403 char *new_ptr;
404 if (!(new_ptr = static_cast<char *>(my_realloc(
405 STRING_PSI_MEMORY_KEY, m_ptr, arg_length, MYF(0))))) {
407 real_alloc(arg_length);
408 } else {
409 m_ptr = new_ptr;
410 m_alloced_length = static_cast<uint32>(arg_length);
411 }
412 }
413 }
414 bool is_alloced() const { return m_is_alloced; }
416 if (&s != this) {
417 /*
418 It is forbidden to do assignments like
419 some_string = substring_of_that_string
420 */
421 assert(!s.uses_buffer_owned_by(this));
422 mem_free();
423 m_ptr = s.m_ptr;
424 m_length = s.m_length;
427 m_is_alloced = false;
428 }
429 return *this;
430 }
431 String &operator=(String &&s) noexcept {
432 if (&s != this) {
433 /*
434 It is forbidden to do assignments like
435 some_string = substring_of_that_string
436 */
437 assert(!s.uses_buffer_owned_by(this));
438 mem_free();
439 m_ptr = s.m_ptr;
440 m_length = s.m_length;
441 m_alloced_length = s.m_alloced_length;
442 m_charset = s.m_charset;
443 // This is the primary difference between move and copy.
444 m_is_alloced = s.m_is_alloced;
445 s.m_is_alloced = false;
446 }
447 return *this;
448 }
449 /**
450 Takeover the buffer owned by another string.
451 "this" becomes the owner of the buffer and
452 is further responsible to free it.
453 The string "s" is detached from the buffer (cleared).
454
455 @param s - a String object to steal buffer from.
456 */
457 void takeover(String &s) {
458 assert(this != &s);
459 // Make sure buffers of the two Strings do not overlap
460 assert(!s.uses_buffer_owned_by(this));
461 mem_free();
462 m_ptr = s.m_ptr;
463 m_length = s.m_length;
467 s.m_ptr = nullptr;
468 s.m_alloced_length = 0;
469 s.m_length = 0;
470 s.m_is_alloced = false;
471 }
472
473 bool copy(); // Alloc string if not alloced
474 bool copy(const String &s); // Allocate new string
475 // Allocate new string
476 bool copy(const char *s, size_t arg_length, const CHARSET_INFO *cs);
477 static bool needs_conversion(size_t arg_length, const CHARSET_INFO *cs_from,
478 const CHARSET_INFO *cs_to, size_t *offset);
479 bool needs_conversion(const CHARSET_INFO *cs_to) const {
480 size_t offset;
481 return needs_conversion(length(), charset(), cs_to, &offset);
482 }
483 bool is_valid_string(const CHARSET_INFO *cs_to) const {
484 size_t valid_length;
485 bool length_error;
486 return !validate_string(cs_to, ptr(), length(), &valid_length,
487 &length_error);
488 }
489 static bool needs_conversion_on_storage(size_t arg_length,
490 const CHARSET_INFO *cs_from,
491 const CHARSET_INFO *cs_to);
492 bool copy_aligned(const char *s, size_t arg_length, size_t offset,
493 const CHARSET_INFO *cs);
494 bool set_or_copy_aligned(const char *s, size_t arg_length,
495 const CHARSET_INFO *cs);
496 bool copy(const char *s, size_t arg_length, const CHARSET_INFO *csfrom,
497 const CHARSET_INFO *csto, uint *errors);
498 bool append(const String &s);
499 bool append(std::string_view s) { return append(s.data(), s.size()); }
500 bool append(LEX_STRING *ls) { return append(ls->str, ls->length); }
501 bool append(Simple_cstring str) { return append(str.ptr(), str.length()); }
502 bool append(const char *s, size_t arg_length);
503 bool append(const char *s, size_t arg_length, const CHARSET_INFO *cs);
504 bool append_ulonglong(ulonglong val);
505 bool append_longlong(longlong val);
506 bool append_with_prefill(const char *s, size_t arg_length, size_t full_length,
507 char fill_char);
508 bool append_parenthesized(int64_t nr);
509 /**
510 Search for a substring.
511
512 @param search substring to search for
513 @param offset starting point, bytes from the start of the string
514
515 @return byte offset to the substring from the start of this string
516 @retval -1 if the substring is not found starting from the offset
517 */
518 int strstr(const String &search, size_t offset = 0) const;
519 /**
520 Reverse search for a substring.
521
522 @param search substring to search for
523 @param offset starting point, bytes from the start of the string
524
525 @return byte offset to the substring from the start of this string
526 @retval -1 if the substring is not found starting from the offset
527 */
528 int strrstr(const String &search, size_t offset = 0) const;
529 /**
530 * Returns substring of given characters lenght, starting at given character
531 * offset. Note that parameter indexes are character indexes and not byte
532 * indexes.
533 */
534 String substr(int offset, int count) const;
535
536 bool replace(size_t offset, size_t arg_length, const char *to, size_t length);
537 bool replace(size_t offset, size_t arg_length, const String &to);
538 bool append(char chr) {
540 m_ptr[m_length++] = chr;
541 } else {
542 if (mem_realloc_exp(m_length + 1)) return true;
543 m_ptr[m_length++] = chr;
544 }
545 return false;
546 }
547 bool fill(size_t max_length, char fill);
548 friend int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs);
549 friend int stringcmp(const String *a, const String *b);
550 friend String *copy_if_not_alloced(String *to, String *from,
551 size_t from_length);
552 size_t numchars() const;
553 size_t charpos(size_t i, size_t offset = 0) const;
554
555 bool reserve(size_t space_needed) {
558 }
559 return false;
560 }
561 bool reserve(size_t space_needed, size_t grow_by);
562
563 /* Inline (general) functions used by the protocol functions */
564
565 char *prep_append(size_t arg_length, size_t step_alloc) {
566 size_t new_length = arg_length + m_length;
567 if (new_length > m_alloced_length) {
568 if (mem_realloc(new_length + step_alloc)) return nullptr;
569 }
570 size_t old_length = m_length;
571 m_length += arg_length;
572 return m_ptr + old_length; /* Area to use */
573 }
574
575 bool append(const char *s, size_t arg_length, size_t step_alloc) {
576 size_t new_length = arg_length + m_length;
577 if (new_length > m_alloced_length &&
578 mem_realloc_exp(new_length + step_alloc))
579 return true;
580 memcpy(m_ptr + m_length, s, arg_length);
581 m_length += arg_length;
582 return false;
583 }
584 void print(String *print) const;
585
586 /* Swap two string objects. Efficient way to exchange data without memcpy. */
587 void swap(String &s) noexcept;
588
589 bool uses_buffer_owned_by(const String *s) const {
590 return (s->m_is_alloced && m_ptr >= s->m_ptr &&
591 m_ptr < s->m_ptr + s->m_length);
592 }
593 bool is_ascii() const {
594 if (length() == 0) return true;
595 if (charset()->mbminlen > 1) return false;
596 for (const char *c = ptr(), *end = c + length(); c < end; c++) {
597 if (!my_isascii(*c)) return false;
598 }
599 return true;
600 }
601 /**
602 Make a zero-terminated copy of our value,allocated in the specified MEM_ROOT
603
604 @param root MEM_ROOT to allocate the result
605
606 @return allocated string or NULL
607 */
608 char *dup(MEM_ROOT *root) const;
609};
610
611static inline void swap(String &a, String &b) noexcept { a.swap(b); }
612
613static inline std::string to_string(const String &str) {
614 return std::string(str.ptr(), str.length());
615}
616
617/**
618 String class wrapper with a preallocated buffer of size buff_sz
619
620 This class allows to replace sequences of:
621 char buff[12345];
622 String str(buff, sizeof(buff));
623 str.length(0);
624 with a simple equivalent declaration:
625 StringBuffer<12345> str;
626*/
627
628template <size_t buff_sz>
629class StringBuffer : public String {
630 char buff[buff_sz];
631
632 public:
634 explicit StringBuffer(const CHARSET_INFO *cs) : String(buff, buff_sz, cs) {
635 length(0);
636 }
637 StringBuffer(const char *str, size_t length, const CHARSET_INFO *cs)
638 : String(buff, buff_sz, cs) {
639 set(str, length, cs);
640 }
641};
642
643static inline bool check_if_only_end_space(const CHARSET_INFO *cs,
644 const char *str, const char *end) {
645 return str + cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
646}
647
649 LEX_CSTRING cstr = {s.str, s.length};
650 return cstr;
651}
652
654 LEX_STRING str = {const_cast<char *>(s.str), s.length};
655 return str;
656}
657
658inline LEX_CSTRING to_lex_cstring(const char *s) {
659 LEX_CSTRING cstr = {s, s != nullptr ? strlen(s) : 0};
660 return cstr;
661}
662
663bool append_escaped(String *to_str, const String *from_str);
664
665#endif /* SQL_STRING_INCLUDED */
A wrapper class for null-terminated constant strings.
Definition: sql_string.h:73
Simple_cstring(const LEX_STRING arg)
Definition: sql_string.h:94
const char * m_str
Definition: sql_string.h:75
bool eq_bin(const Simple_cstring other) const
Compare to another Simple_cstring.
Definition: sql_string.h:116
const char * ptr() const
Return string buffer.
Definition: sql_string.h:104
bool is_set() const
Check if m_ptr is set.
Definition: sql_string.h:108
void set(const char *str)
Set to a null-terminated string.
Definition: sql_string.h:100
void reset()
Definition: sql_string.h:96
size_t length() const
Return name length.
Definition: sql_string.h:112
void strcpy(char *buff) const
Copy to the given buffer.
Definition: sql_string.h:123
Simple_cstring(const LEX_CSTRING arg)
Definition: sql_string.h:95
Simple_cstring(const char *str_arg, size_t length_arg)
Definition: sql_string.h:91
size_t m_length
Definition: sql_string.h:76
Simple_cstring()
Definition: sql_string.h:90
void set(const char *str_arg, size_t length_arg)
Initialize from a C string whose length is already known.
Definition: sql_string.h:82
String class wrapper with a preallocated buffer of size buff_sz.
Definition: sql_string.h:629
char buff[buff_sz]
Definition: sql_string.h:630
StringBuffer()
Definition: sql_string.h:633
StringBuffer(const CHARSET_INFO *cs)
Definition: sql_string.h:634
StringBuffer(const char *str, size_t length, const CHARSET_INFO *cs)
Definition: sql_string.h:637
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
LEX_CSTRING lex_cstring() const
Definition: sql_string.h:274
size_t next_realloc_exp_size(size_t sz)
Definition: sql_string.cc:138
friend String * copy_if_not_alloced(String *to, String *from, size_t from_length)
Makes a copy of a String's buffer unless it's already heap-allocated.
Definition: sql_string.cc:766
LEX_STRING lex_string()
Definition: sql_string.h:272
char & operator[](size_t i)
Definition: sql_string.h:243
const CHARSET_INFO * m_charset
Definition: sql_string.h:169
bool append_ulonglong(ulonglong val)
Append an unsigned longlong to the string.
Definition: sql_string.cc:488
bool append_longlong(longlong val)
Append a signed longlong to the string.
Definition: sql_string.cc:498
bool alloc(size_t arg_length)
Definition: sql_string.h:387
bool mem_realloc_exp(size_t arg_length)
This function is used by the various append() and replace() member functions, to ensure that function...
Definition: sql_string.cc:162
bool append(const String &s)
Definition: sql_string.cc:445
bool append(LEX_STRING *ls)
Definition: sql_string.h:500
bool set_ascii(const char *str, size_t arg_length)
Definition: sql_string.cc:423
bool is_empty() const
Definition: sql_string.h:245
uint32 m_alloced_length
Definition: sql_string.h:171
bool append(Simple_cstring str)
Definition: sql_string.h:501
bool set(longlong num, const CHARSET_INFO *cs)
Definition: sql_string.h:325
void takeover(String &s)
Takeover the buffer owned by another string.
Definition: sql_string.h:457
void set(const char *str, size_t arg_length, const CHARSET_INFO *cs)
Definition: sql_string.h:307
char * prep_append(size_t arg_length, size_t step_alloc)
Definition: sql_string.h:565
String & operator=(String &&s) noexcept
Definition: sql_string.h:431
bool set(ulonglong num, const CHARSET_INFO *cs)
Definition: sql_string.h:328
void mem_free()
Definition: sql_string.h:377
char * c_ptr_safe()
Definition: sql_string.h:265
void chop()
Definition: sql_string.h:366
bool set_int(longlong num, bool unsigned_flag, const CHARSET_INFO *cs)
Definition: sql_string.cc:168
bool append_parenthesized(int64_t nr)
Append a parenthesized number to String.
Definition: sql_string.cc:546
char * ptr()
Definition: sql_string.h:249
String(String &&str) noexcept
Definition: sql_string.h:213
char * c_ptr_quick()
Definition: sql_string.h:261
bool needs_conversion(const CHARSET_INFO *cs_to) const
Definition: sql_string.h:479
String(const String &str)
Definition: sql_string.h:207
String(char *str, size_t len, const CHARSET_INFO *cs)
Definition: sql_string.h:201
String(const char *str, size_t len, const CHARSET_INFO *cs)
Definition: sql_string.h:195
const CHARSET_INFO * charset() const
Definition: sql_string.h:239
static bool needs_conversion(size_t arg_length, const CHARSET_INFO *cs_from, const CHARSET_INFO *cs_to, size_t *offset)
Definition: sql_string.cc:268
size_t m_length
Definition: sql_string.h:168
String(size_t length_arg)
Definition: sql_string.h:181
bool is_ascii() const
Definition: sql_string.h:593
const char & operator[](size_t i) const
Definition: sql_string.h:242
bool real_alloc(size_t arg_length)
Definition: sql_string.cc:46
int strrstr(const String &search, size_t offset=0) const
Reverse search for a substring.
Definition: sql_string.cc:600
void set_charset(const CHARSET_INFO *charset_arg)
Definition: sql_string.h:238
const char * ptr() const
Definition: sql_string.h:248
String(const char *str, const CHARSET_INFO *cs)
Definition: sql_string.h:189
void set_quick(char *str, size_t arg_length, const CHARSET_INFO *cs)
Definition: sql_string.h:316
bool reserve(size_t space_needed)
Definition: sql_string.h:555
String & operator=(const String &s)
Definition: sql_string.h:415
char * m_ptr
Definition: sql_string.h:167
size_t charpos(size_t i, size_t offset=0) const
Definition: sql_string.cc:568
String()
Definition: sql_string.h:175
friend int stringcmp(const String *a, const String *b)
Definition: sql_string.cc:737
bool append(char chr)
Definition: sql_string.h:538
bool fill(size_t max_length, char fill)
Definition: sql_string.cc:434
bool mem_realloc(size_t arg_length, bool force_on_heap=false)
Allocates a new buffer on the heap for this String.
Definition: sql_string.cc:97
bool append(std::string_view s)
Definition: sql_string.h:499
int strstr(const String &search, size_t offset=0) const
Search for a substring.
Definition: sql_string.cc:574
char * dup(MEM_ROOT *root) const
Make a zero-terminated copy of our value,allocated in the specified MEM_ROOT.
Definition: sql_string.cc:1026
bool append(const char *s, size_t arg_length, size_t step_alloc)
Definition: sql_string.h:575
void swap(String &s) noexcept
Definition: sql_string.cc:1017
char * c_ptr()
Definition: sql_string.h:250
static bool needs_conversion_on_storage(size_t arg_length, const CHARSET_INFO *cs_from, const CHARSET_INFO *cs_to)
Definition: sql_string.cc:291
bool set_or_copy_aligned(const char *s, size_t arg_length, const CHARSET_INFO *cs)
Definition: sql_string.cc:358
void shrink(size_t arg_length)
Definition: sql_string.h:400
bool replace(size_t offset, size_t arg_length, const char *to, size_t length)
Definition: sql_string.cc:646
friend int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs)
Definition: sql_string.cc:714
void print(String *print) const
Definition: sql_string.cc:974
~String()
Definition: sql_string.h:236
void mark_as_const()
Definition: sql_string.h:246
bool append_with_prefill(const char *s, size_t arg_length, size_t full_length, char fill_char)
Definition: sql_string.cc:550
size_t length() const
Definition: sql_string.h:240
size_t alloced_length() const
Definition: sql_string.h:241
size_t numchars() const
Definition: sql_string.cc:564
void length(size_t len)
Definition: sql_string.h:244
bool copy()
Definition: sql_string.cc:191
void set(String &str, size_t offset, size_t arg_length)
Definition: sql_string.h:279
bool copy_aligned(const char *s, size_t arg_length, size_t offset, const CHARSET_INFO *cs)
Definition: sql_string.cc:335
bool m_is_alloced
Definition: sql_string.h:172
bool is_alloced() const
Definition: sql_string.h:414
void mem_claim(bool claim)
Definition: sql_string.h:371
bool is_valid_string(const CHARSET_INFO *cs_to) const
Definition: sql_string.h:483
bool set_real(double num, uint decimals, const CHARSET_INFO *cs)
Sets the contents of this string to the string representation of the given double value.
Definition: sql_string.cc:178
String substr(int offset, int count) const
Returns substring of given characters lenght, starting at given character offset.
Definition: sql_string.cc:623
void set(char *str, size_t arg_length, const CHARSET_INFO *cs)
Points the internal buffer to the supplied one.
Definition: sql_string.h:300
bool uses_buffer_owned_by(const String *s) const
Definition: sql_string.h:589
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:48
A better implementation of the UNIX ctype(3) library.
size_t my_convert(char *to, size_t to_length, const CHARSET_INFO *to_cs, const char *from, size_t from_length, const CHARSET_INFO *from_cs, uint *errors)
Convert a string between two character sets.
Definition: ctype.cc:941
#define my_isascii(c)
Definition: m_ctype.h:645
MYSQL_PLUGIN_IMPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:510
#define MY_SEQ_SPACES
Definition: m_ctype.h:106
Various macros useful for communicating with memory debuggers, such as Valgrind.
void TRASH(void *ptr, size_t length)
Put bad content in memory to be sure it will segfault if dereferenced.
Definition: memory_debugging.h:70
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
long long int longlong
Definition: my_inttypes.h:54
#define MYF(v)
Definition: my_inttypes.h:96
uint32_t uint32
Definition: my_inttypes.h:66
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:80
static int count
Definition: myisam_ftdump.cc:42
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1055
Definition: commit_order_queue.h:33
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
bool space_needed(const THD *thd, const Json_wrapper *value, bool large, size_t *needed)
How much space is needed for a JSON value when it is stored in the binary format.
Definition: json_binary.cc:1536
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
Performance schema instrumentation interface.
Performance schema instrumentation interface.
void my_claim(const void *ptr, bool claim)
Definition: my_malloc.cc:308
void * my_realloc(PSI_memory_key key, void *ptr, size_t size, myf_t flags)
Definition: my_malloc.cc:271
String * copy_if_not_alloced(String *to, String *from, size_t from_length)
Makes a copy of a String's buffer unless it's already heap-allocated.
Definition: sql_string.cc:766
LEX_CSTRING to_lex_cstring(const LEX_STRING &s)
Definition: sql_string.h:648
PSI_memory_key key_memory_String_value
Definition: sql_string.cc:39
static bool check_if_only_end_space(const CHARSET_INFO *cs, const char *str, const char *end)
Definition: sql_string.h:643
size_t well_formed_copy_nchars(const CHARSET_INFO *to_cs, char *to, size_t to_length, const CHARSET_INFO *from_cs, const char *from, size_t from_length, size_t nchars, const char **well_formed_error_pos, const char **cannot_convert_error_pos, const char **from_end_pos)
Definition: sql_string.cc:815
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:611
size_t copy_and_convert(char *to, size_t to_length, const CHARSET_INFO *to_cs, const char *from, size_t from_length, const CHARSET_INFO *from_cs, uint *errors)
Definition: sql_string.h:138
size_t convert_to_printable(char *to, size_t to_len, const char *from, size_t from_len, const CHARSET_INFO *from_cs, size_t nbytes=0)
Convert string to printable ASCII string.
Definition: sql_string.cc:1050
int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs)
Definition: sql_string.cc:714
LEX_STRING to_lex_string(const LEX_CSTRING &s)
Definition: sql_string.h:653
static std::string to_string(const String &str)
Definition: sql_string.h:613
size_t bin_to_hex_str(char *to, size_t to_len, const char *from, size_t from_len)
Convert a buffer to printable HEX encoded string For eg: ABCDEF1234.
Definition: sql_string.cc:1107
#define STRING_PSI_MEMORY_KEY
Definition: sql_string.h:57
bool validate_string(const CHARSET_INFO *cs, const char *str, size_t length, size_t *valid_length, bool *length_error)
Check if an input byte sequence is a valid character string of a given charset.
Definition: sql_string.cc:1157
bool append_escaped(String *to_str, const String *from_str)
Appends from_str to to_str, escaping certain characters.
Definition: sql_string.cc:1199
Definition: m_ctype.h:354
Definition: my_sys.h:340
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:144
Definition: mysql_lex_string.h:39
const char * str
Definition: mysql_lex_string.h:40
size_t length
Definition: mysql_lex_string.h:41
Definition: mysql_lex_string.h:34
char * str
Definition: mysql_lex_string.h:35
size_t length
Definition: mysql_lex_string.h:36
unsigned int uint
Definition: uca-dump.cc:29