MySQL 8.4.3
Source Code Documentation
sql_string.h File Reference

Our own string classes, used pervasively throughout the executor. More...

#include <assert.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <new>
#include <string>
#include <string_view>
#include "lex_string.h"
#include "memory_debugging.h"
#include "my_alloc.h"
#include "my_compiler.h"
#include "my_sys.h"
#include "my_inttypes.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/mysql_lex_string.h"
#include "mysql/psi/psi_memory.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"

Go to the source code of this file.

Classes

class  Simple_cstring
 A wrapper class for null-terminated constant strings. More...
 
class  String
 Using this class is fraught with peril, and you need to be very careful when doing so. More...
 
class  StringBuffer< buff_sz >
 String class wrapper with a preallocated buffer of size buff_sz. More...
 

Macros

#define STRING_PSI_MEMORY_KEY   key_memory_String_value
 

Functions

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. More...
 
int sortcmp (const String *a, const String *b, const CHARSET_INFO *cs)
 
Stringcopy_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. More...
 
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)
 
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)
 
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. More...
 
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. More...
 
static void swap (String &a, String &b) noexcept
 
static std::string to_string (const String &str)
 
static bool check_if_only_end_space (const CHARSET_INFO *cs, const char *str, const char *end)
 
LEX_CSTRING to_lex_cstring (const LEX_STRING &s)
 
LEX_STRING to_lex_string (const LEX_CSTRING &s)
 
LEX_CSTRING to_lex_cstring (const char *s)
 
bool append_escaped (String *to_str, const String *from_str)
 Appends from_str to to_str, escaping certain characters. More...
 

Variables

PSI_memory_key key_memory_String_value
 

Detailed Description

Our own string classes, used pervasively throughout the executor.

See in particular the comment on String before you use anything from here.

Macro Definition Documentation

◆ STRING_PSI_MEMORY_KEY

#define STRING_PSI_MEMORY_KEY   key_memory_String_value

Function Documentation

◆ append_escaped()

bool append_escaped ( String to_str,
const String from_str 
)

Appends from_str to to_str, escaping certain characters.

Parameters
[in,out]to_strThe destination string.
[in]from_strThe source string.
Returns
false on success, true on error.

◆ bin_to_hex_str()

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.

Parameters
tooutput buffer
to_lensize of the output buffer (from_len*2 + 1 or greater)
frominput buffer
from_lensize of the input buffer
Returns
number of bytes in the output string

◆ check_if_only_end_space()

static bool check_if_only_end_space ( const CHARSET_INFO cs,
const char *  str,
const char *  end 
)
inlinestatic

◆ convert_to_printable()

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 
)

Convert string to printable ASCII string.

This function converts input string "from" replacing non-ASCII bytes with hexadecimal sequences ("\xXX") optionally appending "..." to the end of the resulting string. This function used in the ER_TRUNCATED_WRONG_VALUE_FOR_FIELD error messages, e.g. when a string cannot be converted to a result charset.

Parameters
tooutput buffer
to_lensize of the output buffer (8 bytes or greater)
frominput string
from_lensize of the input string
from_csinput charset
nbytesmaximal number of bytes to convert (from_len if 0)
Returns
number of bytes in the output string

◆ copy_and_convert()

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 
)
inline

◆ copy_if_not_alloced()

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.

If the buffer ('str') of 'from' is on the heap, this function returns 'from', possibly re-allocated to be at least from_length bytes long. It is also the case if from==to or to==NULL. Otherwise, this function makes and returns a copy of "from" into "to"; the buffer of "to" is heap-allocated; a pre-condition is that from->str and to->str must point to non-overlapping buffers. The logic behind this complex design, is that a caller, typically a val_str() function, sometimes has an input String ('from') which buffer it wants to modify; but this String's buffer may or not be heap-allocated; if it's not heap-allocated it is possibly in static storage or belongs to an outer context, and thus should not be modified; in that case the caller wants a heap-allocated copy which it can freely modify.

Parameters
todestination string
fromsource string
from_lengthdestination string will hold at least from_length bytes.

◆ sortcmp()

int sortcmp ( const String a,
const String b,
const CHARSET_INFO cs 
)

◆ swap()

static void swap ( String a,
String b 
)
inlinestaticnoexcept

◆ to_lex_cstring() [1/2]

LEX_CSTRING to_lex_cstring ( const char *  s)
inline

◆ to_lex_cstring() [2/2]

LEX_CSTRING to_lex_cstring ( const LEX_STRING s)
inline

◆ to_lex_string()

LEX_STRING to_lex_string ( const LEX_CSTRING s)
inline

◆ to_string()

static std::string to_string ( const String str)
inlinestatic

◆ validate_string()

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.

Parameters
csThe input character set.
strThe input byte sequence to validate.
lengthA byte length of the str.
[out]valid_lengthA byte length of a valid prefix of the str.
[out]length_errorTrue in the case of a character length error: some byte[s] in the input is not a valid prefix for a character, i.e. the byte length of that invalid character is undefined.
Return values
trueif the whole input byte sequence is a valid character string. The length_error output parameter is undefined.
Returns
if the whole input byte sequence is a valid character string then return false else if the length of some character in the input is undefined (MY_CS_ILSEQ) or the last character is truncated (MY_CS_TOOSMALL) then length_error= true; // fatal error! else length_error= false; // non-fatal error: there is no wide character encoding for some input character return true

◆ well_formed_copy_nchars()

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 
)

Variable Documentation

◆ key_memory_String_value

PSI_memory_key key_memory_String_value
extern