MySQL  8.0.26
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 
39 #include "lex_string.h"
40 #include "m_ctype.h" // my_convert
41 #include "m_string.h" // LEX_CSTRING
42 #include "memory_debugging.h"
43 #include "my_alloc.h"
44 #include "my_compiler.h"
45 
46 #include "my_inttypes.h"
48 #include "mysql/mysql_lex_string.h" // LEX_STRING
49 #include "mysql/psi/psi_memory.h"
50 #include "mysql/service_mysql_alloc.h" // my_free
51 
52 struct MEM_ROOT;
53 
54 #ifdef MYSQL_SERVER
56 #define STRING_PSI_MEMORY_KEY key_memory_String_value
57 #else
58 #define STRING_PSI_MEMORY_KEY PSI_NOT_INSTRUMENTED
59 #endif
60 
61 /**
62  A wrapper class for null-terminated constant strings.
63  Constructors make sure that the position of the '\0' terminating byte
64  in m_str is always in sync with m_length.
65 
66  This class must stay as small as possible as we often
67  pass it and its descendants (such as Name_string) into functions
68  using call-by-value evaluation.
69 
70  Don't add new members or virual methods into this class!
71 */
73  private:
74  const char *m_str;
75  size_t m_length;
76 
77  public:
78  /**
79  Initialize from a C string whose length is already known.
80  */
81  void set(const char *str_arg, size_t length_arg) {
82  // NULL is allowed only with length==0
83  assert(str_arg || length_arg == 0);
84  // For non-NULL, make sure length_arg is in sync with '\0' terminator.
85  assert(!str_arg || str_arg[length_arg] == '\0');
86  m_str = str_arg;
87  m_length = length_arg;
88  }
89  Simple_cstring() { set(nullptr, 0); }
90  Simple_cstring(const char *str_arg, size_t length_arg) {
91  set(str_arg, length_arg);
92  }
93  Simple_cstring(const LEX_STRING arg) { set(arg.str, arg.length); }
94  Simple_cstring(const LEX_CSTRING arg) { set(arg.str, arg.length); }
95  void reset() { set(nullptr, 0); }
96  /**
97  Set to a null-terminated string.
98  */
99  void set(const char *str) { set(str, str ? strlen(str) : 0); }
100  /**
101  Return string buffer.
102  */
103  const char *ptr() const { return m_str; }
104  /**
105  Check if m_ptr is set.
106  */
107  bool is_set() const { return m_str != nullptr; }
108  /**
109  Return name length.
110  */
111  size_t length() const { return m_length; }
112  /**
113  Compare to another Simple_cstring.
114  */
115  bool eq_bin(const Simple_cstring other) const {
116  return m_length == other.m_length &&
117  memcmp(m_str, other.m_str, m_length) == 0;
118  }
119  /**
120  Copy to the given buffer
121  */
122  void strcpy(char *buff) const {
123  memcpy(buff, m_str, m_length);
124  buff[m_length] = '\0';
125  }
126 };
127 
128 class String;
129 
130 struct CHARSET_INFO;
131 struct IO_CACHE;
132 
133 bool validate_string(const CHARSET_INFO *cs, const char *str, size_t length,
134  size_t *valid_length, bool *length_error);
135 int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs);
136 String *copy_if_not_alloced(String *to, String *from, size_t from_length);
137 inline size_t copy_and_convert(char *to, size_t to_length,
138  const CHARSET_INFO *to_cs, const char *from,
139  size_t from_length, const CHARSET_INFO *from_cs,
140  uint *errors) {
141  return my_convert(to, to_length, to_cs, from, from_length, from_cs, errors);
142 }
143 size_t well_formed_copy_nchars(const CHARSET_INFO *to_cs, char *to,
144  size_t to_length, const CHARSET_INFO *from_cs,
145  const char *from, size_t from_length,
146  size_t nchars,
147  const char **well_formed_error_pos,
148  const char **cannot_convert_error_pos,
149  const char **from_end_pos);
150 size_t convert_to_printable(char *to, size_t to_len, const char *from,
151  size_t from_len, const CHARSET_INFO *from_cs,
152  size_t nbytes = 0);
153 
154 size_t bin_to_hex_str(char *to, size_t to_len, const char *from,
155  size_t from_len);
156 
157 /**
158  Using this class is fraught with peril, and you need to be very careful
159  when doing so. In particular, copy construction and assignment does not
160  do a deep _nor_ a shallow copy; instead, it makes a _reference_ to the
161  original string that will be invalid as soon as that string goes out of scope.
162  (Move constructiong and assignment is safe, though.) In general, it is
163  probably better not to use this class at all if you can avoid it.
164 */
165 class String {
166  char *m_ptr;
167  size_t m_length;
169  uint32
170  m_alloced_length; // should be size_t, but kept uint32 for size reasons
172 
173  public:
175  : m_ptr(nullptr),
176  m_length(0),
178  m_alloced_length(0),
179  m_is_alloced(false) {}
180  explicit String(size_t length_arg)
181  : m_ptr(nullptr),
182  m_length(0),
184  m_alloced_length(0),
185  m_is_alloced(false) {
186  (void)real_alloc(length_arg);
187  }
188  String(const char *str, const CHARSET_INFO *cs)
189  : m_ptr(const_cast<char *>(str)),
190  m_length(strlen(str)),
191  m_charset(cs),
192  m_alloced_length(0),
193  m_is_alloced(false) {}
194  String(const char *str, size_t len, const CHARSET_INFO *cs)
195  : m_ptr(const_cast<char *>(str)),
196  m_length(len),
197  m_charset(cs),
198  m_alloced_length(0),
199  m_is_alloced(false) {}
200  String(char *str, size_t len, const CHARSET_INFO *cs)
201  : m_ptr(str),
202  m_length(len),
203  m_charset(cs),
204  m_alloced_length(static_cast<uint32>(len)),
205  m_is_alloced(false) {}
206  String(const String &str)
207  : m_ptr(str.m_ptr),
211  m_is_alloced(false) {}
212  String(String &&str) noexcept
213  : m_ptr(str.m_ptr),
214  m_length(str.m_length),
215  m_charset(str.m_charset),
216  m_alloced_length(str.m_alloced_length),
217  m_is_alloced(str.m_is_alloced) {
218  str.m_is_alloced = false;
219  }
220  static void *operator new(size_t size, MEM_ROOT *mem_root,
221  const std::nothrow_t &arg MY_ATTRIBUTE((unused)) =
222  std::nothrow) noexcept {
223  return mem_root->Alloc(size);
224  }
225  static void operator delete(void *ptr_arg, size_t size) {
226  (void)ptr_arg;
227  (void)size;
228  TRASH(ptr_arg, size);
229  }
230 
231  static void operator delete(
232  void *, MEM_ROOT *, const std::nothrow_t &) noexcept { /* never called */
233  }
234 
235  ~String() { mem_free(); }
236 
237  void set_charset(const CHARSET_INFO *charset_arg) { m_charset = charset_arg; }
238  const CHARSET_INFO *charset() const { return m_charset; }
239  size_t length() const { return m_length; }
240  size_t alloced_length() const { return m_alloced_length; }
241  const char &operator[](size_t i) const { return m_ptr[i]; }
242  char &operator[](size_t i) { return m_ptr[i]; }
243  void length(size_t len) { m_length = len; }
244  bool is_empty() const { return (m_length == 0); }
246  /* Returns a pointer to data, may not include NULL terminating character. */
247  const char *ptr() const { return m_ptr; }
248  char *ptr() { return m_ptr; }
249  char *c_ptr() {
250  assert(!m_is_alloced || !m_ptr || !m_alloced_length ||
251  (m_alloced_length >= (m_length + 1)));
252 
253  /*
254  Should be safe, but in case valgrind complains on this line, it means
255  there is a misuse of c_ptr(). Please prefer <ptr(), length()> instead.
256  */
257  if (!m_ptr || m_ptr[m_length]) (void)mem_realloc(m_length);
258  return m_ptr;
259  }
260  char *c_ptr_quick() {
262  return m_ptr;
263  }
264  char *c_ptr_safe() {
266  m_ptr[m_length] = 0;
267  else
268  (void)mem_realloc(m_length);
269  return m_ptr;
270  }
271  LEX_STRING lex_string() { return {m_ptr, length()}; }
272 
275  return lex_cstring;
276  }
277 
278  void set(String &str, size_t offset, size_t arg_length) {
279  assert(&str != this);
280  mem_free();
281  m_ptr = str.ptr() + offset;
282  m_length = arg_length;
283  m_is_alloced = false;
284  if (str.m_alloced_length)
285  m_alloced_length = str.m_alloced_length - static_cast<uint32>(offset);
286  else
287  m_alloced_length = 0;
288  m_charset = str.m_charset;
289  }
290 
291  /**
292  Points the internal buffer to the supplied one. The old buffer is freed.
293  @param str Pointer to the new buffer.
294  @param arg_length Length of the new buffer in characters, excluding any
295  null character.
296  @param cs Character set to use for interpreting string data.
297  @note The new buffer will not be null terminated.
298  */
299  void set(char *str, size_t arg_length, const CHARSET_INFO *cs) {
300  mem_free();
301  m_ptr = str;
302  m_length = m_alloced_length = static_cast<uint32>(arg_length);
303  m_is_alloced = false;
304  m_charset = cs;
305  }
306  void set(const char *str, size_t arg_length, const CHARSET_INFO *cs) {
307  mem_free();
308  m_ptr = const_cast<char *>(str);
309  m_length = arg_length;
310  m_alloced_length = 0;
311  m_is_alloced = false;
312  m_charset = cs;
313  }
314  bool set_ascii(const char *str, size_t arg_length);
315  void set_quick(char *str, size_t arg_length, const CHARSET_INFO *cs) {
316  if (!m_is_alloced) {
317  m_ptr = str;
318  m_length = arg_length;
319  m_alloced_length = static_cast<uint32>(arg_length);
320  }
321  m_charset = cs;
322  }
323  bool set_int(longlong num, bool unsigned_flag, const CHARSET_INFO *cs);
324  bool set(longlong num, const CHARSET_INFO *cs) {
325  return set_int(num, false, cs);
326  }
327  bool set(ulonglong num, const CHARSET_INFO *cs) {
328  return set_int((longlong)num, true, cs);
329  }
330 
331  /**
332  Sets the contents of this string to the string representation of the given
333  double value.
334 
335  @param num the double value
336  @param decimals the number of decimals
337  @param cs the character set of the string
338  @return false on success, true on error
339  */
340  bool set_real(double num, uint decimals, const CHARSET_INFO *cs);
341 
342  /*
343  PMG 2004.11.12
344  This is a method that works the same as perl's "chop". It simply
345  drops the last byte of a string. This is useful in the case
346  of the federated storage handler where I'm building a unknown
347  number, list of values and fields to be used in a sql insert
348  statement to be run on the remote server, and have a comma after each.
349  When the list is complete, I "chop" off the trailing comma
350 
351  ex.
352  String stringobj;
353  stringobj.append("VALUES ('foo', 'fi', 'fo',");
354  stringobj.chop();
355  stringobj.append(")");
356 
357  In this case, the value of string was:
358 
359  VALUES ('foo', 'fi', 'fo',
360  VALUES ('foo', 'fi', 'fo'
361  VALUES ('foo', 'fi', 'fo')
362 
363  This is not safe to call when the string ends in a multi-byte character!
364  */
365  void chop() {
366  m_length--;
367  m_ptr[m_length] = '\0';
368  }
369 
370  void mem_claim(bool claim) {
371  if (m_is_alloced) {
372  my_claim(m_ptr, claim);
373  }
374  }
375 
376  void mem_free() {
377  if (m_is_alloced) {
378  m_is_alloced = false;
379  m_alloced_length = 0;
380  my_free(m_ptr);
381  m_ptr = nullptr;
382  m_length = 0; /* Safety */
383  }
384  }
385 
386  bool alloc(size_t arg_length) {
387  if (arg_length < m_alloced_length) return false;
388  return real_alloc(arg_length);
389  }
390  bool real_alloc(size_t arg_length); // Empties old string
391  bool mem_realloc(size_t arg_length, bool force_on_heap = false);
392 
393  private:
394  size_t next_realloc_exp_size(size_t sz);
395  bool mem_realloc_exp(size_t arg_length);
396 
397  public:
398  // Shrink the buffer, but only if it is allocated on the heap.
399  void shrink(size_t arg_length) {
400  if (!is_alloced()) return;
401  if (arg_length < m_alloced_length) {
402  char *new_ptr;
403  if (!(new_ptr = static_cast<char *>(my_realloc(
404  STRING_PSI_MEMORY_KEY, m_ptr, arg_length, MYF(0))))) {
405  m_alloced_length = 0;
406  real_alloc(arg_length);
407  } else {
408  m_ptr = new_ptr;
409  m_alloced_length = static_cast<uint32>(arg_length);
410  }
411  }
412  }
413  bool is_alloced() const { return m_is_alloced; }
414  String &operator=(const String &s) {
415  if (&s != this) {
416  /*
417  It is forbidden to do assignments like
418  some_string = substring_of_that_string
419  */
420  assert(!s.uses_buffer_owned_by(this));
421  mem_free();
422  m_ptr = s.m_ptr;
423  m_length = s.m_length;
425  m_charset = s.m_charset;
426  m_is_alloced = false;
427  }
428  return *this;
429  }
430  String &operator=(String &&s) noexcept {
431  if (&s != this) {
432  /*
433  It is forbidden to do assignments like
434  some_string = substring_of_that_string
435  */
436  assert(!s.uses_buffer_owned_by(this));
437  mem_free();
438  m_ptr = s.m_ptr;
439  m_length = s.m_length;
440  m_alloced_length = s.m_alloced_length;
441  m_charset = s.m_charset;
442  // This is the primary difference between move and copy.
443  m_is_alloced = s.m_is_alloced;
444  s.m_is_alloced = false;
445  }
446  return *this;
447  }
448  /**
449  Takeover the buffer owned by another string.
450  "this" becomes the owner of the buffer and
451  is further responsible to free it.
452  The string "s" is detached from the buffer (cleared).
453 
454  @param s - a String object to steal buffer from.
455  */
456  void takeover(String &s) {
457  assert(this != &s);
458  // Make sure buffers of the two Strings do not overlap
459  assert(!s.uses_buffer_owned_by(this));
460  mem_free();
461  m_ptr = s.m_ptr;
462  m_length = s.m_length;
465  m_charset = s.m_charset;
466  s.m_ptr = nullptr;
467  s.m_alloced_length = 0;
468  s.m_length = 0;
469  s.m_is_alloced = false;
470  }
471 
472  bool copy(); // Alloc string if not alloced
473  bool copy(const String &s); // Allocate new string
474  // Allocate new string
475  bool copy(const char *s, size_t arg_length, const CHARSET_INFO *cs);
476  static bool needs_conversion(size_t arg_length, const CHARSET_INFO *cs_from,
477  const CHARSET_INFO *cs_to, size_t *offset);
478  bool needs_conversion(const CHARSET_INFO *cs_to) const {
479  size_t offset;
480  return needs_conversion(length(), charset(), cs_to, &offset);
481  }
482  bool is_valid_string(const CHARSET_INFO *cs_to) const {
483  size_t valid_length;
484  bool length_error;
485  return !validate_string(cs_to, ptr(), length(), &valid_length,
486  &length_error);
487  }
488  static bool needs_conversion_on_storage(size_t arg_length,
489  const CHARSET_INFO *cs_from,
490  const CHARSET_INFO *cs_to);
491  bool copy_aligned(const char *s, size_t arg_length, size_t offset,
492  const CHARSET_INFO *cs);
493  bool set_or_copy_aligned(const char *s, size_t arg_length,
494  const CHARSET_INFO *cs);
495  bool copy(const char *s, size_t arg_length, const CHARSET_INFO *csfrom,
496  const CHARSET_INFO *csto, uint *errors);
497  bool append(const String &s);
498  bool append(const char *s);
499  bool append(LEX_STRING *ls) { return append(ls->str, ls->length); }
500  bool append(Simple_cstring str) { return append(str.ptr(), str.length()); }
501  bool append(const char *s, size_t arg_length);
502  bool append(const char *s, size_t arg_length, const CHARSET_INFO *cs);
503  bool append_ulonglong(ulonglong val);
504  bool append_longlong(longlong val);
505  bool append_with_prefill(const char *s, size_t arg_length, size_t full_length,
506  char fill_char);
507  bool append_parenthesized(int64_t nr);
508  /**
509  Search for a substring.
510 
511  @param search substring to search for
512  @param offset starting point, bytes from the start of the string
513 
514  @return byte offset to the substring from the start of this string
515  @retval -1 if the substring is not found starting from the offset
516  */
517  int strstr(const String &search, size_t offset = 0) const;
518  /**
519  Reverse search for a substring.
520 
521  @param search substring to search for
522  @param offset starting point, bytes from the start of the string
523 
524  @return byte offset to the substring from the start of this string
525  @retval -1 if the substring is not found starting from the offset
526  */
527  int strrstr(const String &search, size_t offset = 0) const;
528  /**
529  * Returns substring of given characters lenght, starting at given character
530  * offset. Note that parameter indexes are character indexes and not byte
531  * indexes.
532  */
533  String substr(int offset, int count) const;
534 
535  bool replace(size_t offset, size_t arg_length, const char *to, size_t length);
536  bool replace(size_t offset, size_t arg_length, const String &to);
537  bool append(char chr) {
538  if (m_length < m_alloced_length) {
539  m_ptr[m_length++] = chr;
540  } else {
541  if (mem_realloc_exp(m_length + 1)) return true;
542  m_ptr[m_length++] = chr;
543  }
544  return false;
545  }
546  bool fill(size_t max_length, char fill);
547  friend int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs);
548  friend int stringcmp(const String *a, const String *b);
549  friend String *copy_if_not_alloced(String *to, String *from,
550  size_t from_length);
551  size_t numchars() const;
552  size_t charpos(size_t i, size_t offset = 0) const;
553 
554  bool reserve(size_t space_needed) {
557  }
558  return false;
559  }
560  bool reserve(size_t space_needed, size_t grow_by);
561 
562  /* Inline (general) functions used by the protocol functions */
563 
564  char *prep_append(size_t arg_length, size_t step_alloc) {
565  size_t new_length = arg_length + m_length;
566  if (new_length > m_alloced_length) {
567  if (mem_realloc(new_length + step_alloc)) return nullptr;
568  }
569  size_t old_length = m_length;
570  m_length += arg_length;
571  return m_ptr + old_length; /* Area to use */
572  }
573 
574  bool append(const char *s, size_t arg_length, size_t step_alloc) {
575  size_t new_length = arg_length + m_length;
576  if (new_length > m_alloced_length &&
577  mem_realloc_exp(new_length + step_alloc))
578  return true;
579  memcpy(m_ptr + m_length, s, arg_length);
580  m_length += arg_length;
581  return false;
582  }
583  void print(String *print) const;
584 
585  /* Swap two string objects. Efficient way to exchange data without memcpy. */
586  void swap(String &s) noexcept;
587 
588  bool uses_buffer_owned_by(const String *s) const {
589  return (s->m_is_alloced && m_ptr >= s->m_ptr &&
590  m_ptr < s->m_ptr + s->m_length);
591  }
592  bool is_ascii() const {
593  if (length() == 0) return true;
594  if (charset()->mbminlen > 1) return false;
595  for (const char *c = ptr(), *end = c + length(); c < end; c++) {
596  if (!my_isascii(*c)) return false;
597  }
598  return true;
599  }
600  /**
601  Make a zero-terminated copy of our value,allocated in the specified MEM_ROOT
602 
603  @param root MEM_ROOT to allocate the result
604 
605  @return allocated string or NULL
606  */
607  char *dup(MEM_ROOT *root) const;
608 };
609 
610 static inline void swap(String &a, String &b) noexcept { a.swap(b); }
611 
612 static inline std::string to_string(const String &str) {
613  return std::string(str.ptr(), str.length());
614 }
615 
616 /**
617  String class wrapper with a preallocated buffer of size buff_sz
618 
619  This class allows to replace sequences of:
620  char buff[12345];
621  String str(buff, sizeof(buff));
622  str.length(0);
623  with a simple equivalent declaration:
624  StringBuffer<12345> str;
625 */
626 
627 template <size_t buff_sz>
628 class StringBuffer : public String {
629  char buff[buff_sz];
630 
631  public:
632  StringBuffer() : String(buff, buff_sz, &my_charset_bin) { length(0); }
633  explicit StringBuffer(const CHARSET_INFO *cs) : String(buff, buff_sz, cs) {
634  length(0);
635  }
636  StringBuffer(const char *str, size_t length, const CHARSET_INFO *cs)
637  : String(buff, buff_sz, cs) {
638  set(str, length, cs);
639  }
640 };
641 
642 static inline bool check_if_only_end_space(const CHARSET_INFO *cs,
643  const char *str, const char *end) {
644  return str + cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
645 }
646 
648  LEX_CSTRING cstr = {s.str, s.length};
649  return cstr;
650 }
651 
653  LEX_STRING str = {const_cast<char *>(s.str), s.length};
654  return str;
655 }
656 
657 inline LEX_CSTRING to_lex_cstring(const char *s) {
658  LEX_CSTRING cstr = {s, s != nullptr ? strlen(s) : 0};
659  return cstr;
660 }
661 
662 bool append_escaped(String *to_str, const String *from_str);
663 
664 #endif /* SQL_STRING_INCLUDED */
A wrapper class for null-terminated constant strings.
Definition: sql_string.h:72
Simple_cstring(const LEX_STRING arg)
Definition: sql_string.h:93
const char * m_str
Definition: sql_string.h:74
bool eq_bin(const Simple_cstring other) const
Compare to another Simple_cstring.
Definition: sql_string.h:115
const char * ptr() const
Return string buffer.
Definition: sql_string.h:103
bool is_set() const
Check if m_ptr is set.
Definition: sql_string.h:107
void set(const char *str)
Set to a null-terminated string.
Definition: sql_string.h:99
void reset()
Definition: sql_string.h:95
size_t length() const
Return name length.
Definition: sql_string.h:111
void strcpy(char *buff) const
Copy to the given buffer.
Definition: sql_string.h:122
Simple_cstring(const LEX_CSTRING arg)
Definition: sql_string.h:94
Simple_cstring(const char *str_arg, size_t length_arg)
Definition: sql_string.h:90
size_t m_length
Definition: sql_string.h:75
Simple_cstring()
Definition: sql_string.h:89
void set(const char *str_arg, size_t length_arg)
Initialize from a C string whose length is already known.
Definition: sql_string.h:81
String class wrapper with a preallocated buffer of size buff_sz.
Definition: sql_string.h:628
char buff[buff_sz]
Definition: sql_string.h:629
StringBuffer()
Definition: sql_string.h:632
StringBuffer(const CHARSET_INFO *cs)
Definition: sql_string.h:633
StringBuffer(const char *str, size_t length, const CHARSET_INFO *cs)
Definition: sql_string.h:636
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:165
LEX_CSTRING lex_cstring() const
Definition: sql_string.h:273
size_t next_realloc_exp_size(size_t sz)
Definition: sql_string.cc:138
LEX_STRING lex_string()
Definition: sql_string.h:271
const CHARSET_INFO * m_charset
Definition: sql_string.h:168
bool append_ulonglong(ulonglong val)
Append an unsigned longlong to the string.
Definition: sql_string.cc:494
bool append_longlong(longlong val)
Append a signed longlong to the string.
Definition: sql_string.cc:504
char * ptr()
Definition: sql_string.h:248
bool alloc(size_t arg_length)
Definition: sql_string.h:386
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:499
bool set_ascii(const char *str, size_t arg_length)
Definition: sql_string.cc:423
bool is_empty() const
Definition: sql_string.h:244
uint32 m_alloced_length
Definition: sql_string.h:170
bool append(Simple_cstring str)
Definition: sql_string.h:500
bool set(longlong num, const CHARSET_INFO *cs)
Definition: sql_string.h:324
void takeover(String &s)
Takeover the buffer owned by another string.
Definition: sql_string.h:456
char & operator[](size_t i)
Definition: sql_string.h:242
void set(const char *str, size_t arg_length, const CHARSET_INFO *cs)
Definition: sql_string.h:306
bool set(ulonglong num, const CHARSET_INFO *cs)
Definition: sql_string.h:327
void mem_free()
Definition: sql_string.h:376
void chop()
Definition: sql_string.h:365
const char * ptr() const
Definition: sql_string.h:247
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:772
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:552
String(String &&str) noexcept
Definition: sql_string.h:212
bool needs_conversion(const CHARSET_INFO *cs_to) const
Definition: sql_string.h:478
String(const String &str)
Definition: sql_string.h:206
String(char *str, size_t len, const CHARSET_INFO *cs)
Definition: sql_string.h:200
String(const char *str, size_t len, const CHARSET_INFO *cs)
Definition: sql_string.h:194
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:167
String(size_t length_arg)
Definition: sql_string.h:180
bool is_ascii() const
Definition: sql_string.h:592
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:606
void set_charset(const CHARSET_INFO *charset_arg)
Definition: sql_string.h:237
String(const char *str, const CHARSET_INFO *cs)
Definition: sql_string.h:188
void set_quick(char *str, size_t arg_length, const CHARSET_INFO *cs)
Definition: sql_string.h:315
bool reserve(size_t space_needed)
Definition: sql_string.h:554
char * prep_append(size_t arg_length, size_t step_alloc)
Definition: sql_string.h:564
char * m_ptr
Definition: sql_string.h:166
size_t charpos(size_t i, size_t offset=0) const
Definition: sql_string.cc:574
String()
Definition: sql_string.h:174
friend int stringcmp(const String *a, const String *b)
Definition: sql_string.cc:743
bool append(char chr)
Definition: sql_string.h:537
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
char * c_ptr_quick()
Definition: sql_string.h:260
char * c_ptr_safe()
Definition: sql_string.h:264
int strstr(const String &search, size_t offset=0) const
Search for a substring.
Definition: sql_string.cc:580
char * dup(MEM_ROOT *root) const
Make a zero-terminated copy of our value,allocated in the specified MEM_ROOT.
Definition: sql_string.cc:1033
bool append(const char *s, size_t arg_length, size_t step_alloc)
Definition: sql_string.h:574
void swap(String &s) noexcept
Definition: sql_string.cc:1024
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
const char & operator[](size_t i) const
Definition: sql_string.h:241
String & operator=(String &&s) noexcept
Definition: sql_string.h:430
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:399
bool replace(size_t offset, size_t arg_length, const char *to, size_t length)
Definition: sql_string.cc:652
friend int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs)
Definition: sql_string.cc:720
void print(String *print) const
Definition: sql_string.cc:981
~String()
Definition: sql_string.h:235
void mark_as_const()
Definition: sql_string.h:245
bool append_with_prefill(const char *s, size_t arg_length, size_t full_length, char fill_char)
Definition: sql_string.cc:556
size_t length() const
Definition: sql_string.h:239
size_t alloced_length() const
Definition: sql_string.h:240
size_t numchars() const
Definition: sql_string.cc:570
void length(size_t len)
Definition: sql_string.h:243
bool copy()
Definition: sql_string.cc:191
void set(String &str, size_t offset, size_t arg_length)
Definition: sql_string.h:278
const CHARSET_INFO * charset() const
Definition: sql_string.h:238
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:171
bool is_alloced() const
Definition: sql_string.h:413
char * c_ptr()
Definition: sql_string.h:249
void mem_claim(bool claim)
Definition: sql_string.h:370
bool is_valid_string(const CHARSET_INFO *cs_to) const
Definition: sql_string.h:482
String & operator=(const String &s)
Definition: sql_string.h:414
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:629
void set(char *str, size_t arg_length, const CHARSET_INFO *cs)
Points the internal buffer to the supplied one.
Definition: sql_string.h:299
bool uses_buffer_owned_by(const String *s) const
Definition: sql_string.h:588
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
Dialog Client Authentication nullptr
Definition: dialog.cc:353
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:934
#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:1022
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:188
Performance schema instrumentation interface.
Performance schema instrumentation interface.
void my_claim(const void *ptr, bool claim)
Definition: my_malloc.cc:129
void * my_realloc(PSI_memory_key key, void *ptr, size_t size, myf_t flags)
Definition: my_malloc.cc:94
LEX_CSTRING to_lex_cstring(const LEX_STRING &s)
Definition: sql_string.h:647
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:642
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:772
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:821
static void swap(String &a, String &b) noexcept
Definition: sql_string.h:610
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:137
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:1057
int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs)
Definition: sql_string.cc:720
LEX_STRING to_lex_string(const LEX_CSTRING &s)
Definition: sql_string.h:652
static std::string to_string(const String &str)
Definition: sql_string.h:612
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:1114
#define STRING_PSI_MEMORY_KEY
Definition: sql_string.h:56
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:1164
bool append_escaped(String *to_str, const String *from_str)
Appends from_str to to_str, escaping certain characters.
Definition: sql_string.cc:1206
Definition: m_ctype.h:354
Definition: my_sys.h:344
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:135
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