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