MySQL 9.1.0
Source Code Documentation
strfunc.h File Reference
#include <stddef.h>
#include <sys/types.h>
#include <cstring>
#include <utility>
#include "lex_string.h"
#include "my_inttypes.h"
#include "mysql/mysql_lex_string.h"
#include "mysql/strings/m_ctype.h"
#include "sql_string.h"
#include "template_utils.h"

Go to the source code of this file.

Functions

ulonglong find_set (const TYPELIB *lib, const char *x, size_t length, const CHARSET_INFO *cs, const char **err_pos, uint *err_len, bool *set_warning)
 
uint find_type (const TYPELIB *lib, const char *find, size_t length, bool part_match)
 
uint find_type2 (const TYPELIB *lib, const char *find, size_t length, const CHARSET_INFO *cs)
 
uint check_word (TYPELIB *lib, const char *val, const char *end, const char **end_of_word)
 
char * flagset_to_string (THD *thd, LEX_STRING *result, ulonglong set, const char *lib[])
 
char * set_to_string (THD *thd, LEX_STRING *result, ulonglong set, const char *lib[])
 
char * set_to_string (THD *thd, LEX_STRING *result, ulonglong set, const char *lib[], bool quoted)
 
size_t strconvert (const CHARSET_INFO *from_cs, const char *from, CHARSET_INFO *to_cs, char *to, size_t to_length, uint *errors)
 
bool copy_string (MEM_ROOT *mem_root, String *dst, const String *src)
 
template<class STDSTRINGLIKE_TYPE >
MYSQL_LEX_CSTRING lex_cstring_handle (const STDSTRINGLIKE_TYPE &s)
 Return a LEX_CSTRING handle to a std::string like (meaning something which has the c_str() and length() member functions). More...
 
template<class STRLIKE_TYPE >
STRLIKE_TYPE casedn (const CHARSET_INFO *ci, STRLIKE_TYPE &&s)
 Lowercase a string according to charset. More...
 
template<class STRLIKE_TYPE >
STRLIKE_TYPE casedn (const CHARSET_INFO *ci, const STRLIKE_TYPE &src)
 Lowercase a string according to charset. More...
 
LEX_STRINGmake_lex_string_root (MEM_ROOT *mem_root, const char *str, size_t length)
 Create a LEX_STRING in a MEM_ROOT and copy the given string into it. More...
 
bool lex_string_strmake (MEM_ROOT *mem_root, LEX_STRING *lex_str, const char *str, size_t length)
 Copy the given string into a LEX_STRING, allocating it in the given MEM_ROOT. More...
 
bool lex_string_strmake (MEM_ROOT *mem_root, LEX_CSTRING *lex_str, const char *str, size_t length)
 Copy the given string into a LEX_CSTRING, allocating it in the given MEM_ROOT. More...
 
template<class LEX_STRING_TYPE >
LEX_STRING_TYPE LexStringDupRoot (MEM_ROOT *mem_root, LEX_STRING_TYPE s)
 Utility function for copying a LEX_STRING_TYPE (either LEX_STRING or LEX_CSTRING) onto a mem_root. More...
 
template<class LEX_STRING_TYPE >
LEX_STRING_TYPE LexStringDupRootUnlessEmpty (MEM_ROOT *mem_root, LEX_STRING_TYPE s)
 Utility function for copying a LEX_STRING_TYPE (either LEX_STRING or LEX_CSTRING) onto a mem_root, but which does not allocate space for empty strings. More...
 
template<class LEX_STRING_TYPE >
int strnncmp_nopads (const CHARSET_INFO &cs, LEX_STRING_TYPE &&a, LEX_STRING_TYPE &&b)
 Utility function for collating (using strnncoll) two LEX_STRING_TYPEs. More...
 

Function Documentation

◆ casedn() [1/2]

template<class STRLIKE_TYPE >
STRLIKE_TYPE casedn ( const CHARSET_INFO ci,
const STRLIKE_TYPE &  src 
)

Lowercase a string according to charset.

Overload for const T& which copies argument and forwards to T&& overload.

Parameters
cipointer to charset for conversion
srcstring to lower-case
Return values
modifiedcopy of argument

◆ casedn() [2/2]

template<class STRLIKE_TYPE >
STRLIKE_TYPE casedn ( const CHARSET_INFO ci,
STRLIKE_TYPE &&  s 
)

Lowercase a string according to charset.

Parameters
cipointer to charset for conversion
sstring to lower-case
Return values
modifiedargument if r-value
copyof modified argument if lvalue (meaningless, don't use)

◆ check_word()

uint check_word ( TYPELIB lib,
const char *  val,
const char *  end,
const char **  end_of_word 
)

◆ copy_string()

bool copy_string ( MEM_ROOT mem_root,
String dst,
const String src 
)

◆ find_set()

ulonglong find_set ( const TYPELIB lib,
const char *  x,
size_t  length,
const CHARSET_INFO cs,
const char **  err_pos,
uint *  err_len,
bool *  set_warning 
)

◆ find_type()

uint find_type ( const TYPELIB lib,
const char *  find,
size_t  length,
bool  part_match 
)

◆ find_type2()

uint find_type2 ( const TYPELIB lib,
const char *  find,
size_t  length,
const CHARSET_INFO cs 
)

◆ flagset_to_string()

char * flagset_to_string ( THD thd,
LEX_STRING result,
ulonglong  set,
const char *  lib[] 
)

◆ lex_cstring_handle()

template<class STDSTRINGLIKE_TYPE >
MYSQL_LEX_CSTRING lex_cstring_handle ( const STDSTRINGLIKE_TYPE &  s)

Return a LEX_CSTRING handle to a std::string like (meaning something which has the c_str() and length() member functions).

Note that the std::string-like object retains ownership of the character array, and consequently the returned LEX_CSTRING is only valid as long as the std::string-like object is valid.

Parameters
sstd::string-like object
Returns
LEX_CSTRING handle to string

◆ lex_string_strmake() [1/2]

bool lex_string_strmake ( MEM_ROOT mem_root,
LEX_CSTRING lex_str,
const char *  str,
size_t  length 
)

Copy the given string into a LEX_CSTRING, allocating it in the given MEM_ROOT.

Parameters
mem_rootMEM_ROOT where to allocate the string.
lex_strLEX_CSTRING to fill with the copied string.
strstring to be copied into the LEX_CSTRING.
lengthlength of str, in bytes
Returns
true on failure (OOM), false otherwise.

◆ lex_string_strmake() [2/2]

bool lex_string_strmake ( MEM_ROOT mem_root,
LEX_STRING lex_str,
const char *  str,
size_t  length 
)

Copy the given string into a LEX_STRING, allocating it in the given MEM_ROOT.

Parameters
mem_rootMEM_ROOT where to allocate the string.
lex_strLEX_STRING to fill with the copied string.
strstring to be copied into the LEX_STRING.
lengthlength of str, in bytes
Returns
true on failure (OOM), false otherwise.

◆ LexStringDupRoot()

template<class LEX_STRING_TYPE >
LEX_STRING_TYPE LexStringDupRoot ( MEM_ROOT mem_root,
LEX_STRING_TYPE  s 
)
inline

Utility function for copying a LEX_STRING_TYPE (either LEX_STRING or LEX_CSTRING) onto a mem_root.

Parameters
mem_rootWhere to allocate
sSource string to copy.
Returns
LEX_STRING_TYPE referring to the mem_root allocated string.

◆ LexStringDupRootUnlessEmpty()

template<class LEX_STRING_TYPE >
LEX_STRING_TYPE LexStringDupRootUnlessEmpty ( MEM_ROOT mem_root,
LEX_STRING_TYPE  s 
)
inline

Utility function for copying a LEX_STRING_TYPE (either LEX_STRING or LEX_CSTRING) onto a mem_root, but which does not allocate space for empty strings.

If called on a zero-length string EMPTY_CSTR is returned (where str is "").

Parameters
mem_rootWhere to allocate
sSource string to copy.
Returns
LEX_STRING_TYPE referring to the mem_root allocated string, or EMPTY_CSTR.

◆ make_lex_string_root()

LEX_STRING * make_lex_string_root ( MEM_ROOT mem_root,
const char *  str,
size_t  length 
)

Create a LEX_STRING in a MEM_ROOT and copy the given string into it.

Parameters
mem_rootMEM_ROOT where to allocate the LEX_STRING.
strstring to be copied into the LEX_STRING.
lengthlength of str, in bytes
Returns
nullptr on failure, or pointer to the LEX_STRING object

◆ set_to_string() [1/2]

char * set_to_string ( THD thd,
LEX_STRING result,
ulonglong  set,
const char *  lib[] 
)

◆ set_to_string() [2/2]

char * set_to_string ( THD thd,
LEX_STRING result,
ulonglong  set,
const char *  lib[],
bool  quoted 
)

◆ strconvert()

size_t strconvert ( const CHARSET_INFO from_cs,
const char *  from,
CHARSET_INFO to_cs,
char *  to,
size_t  to_length,
uint *  errors 
)

◆ strnncmp_nopads()

template<class LEX_STRING_TYPE >
int strnncmp_nopads ( const CHARSET_INFO cs,
LEX_STRING_TYPE &&  a,
LEX_STRING_TYPE &&  b 
)
inline

Utility function for collating (using strnncoll) two LEX_STRING_TYPEs.

Saves the boiler plate and casting needed when calling the function directly.