MySQL 8.0.30
Source Code Documentation
typelib.cc File Reference

Functions to handle typelib. More...

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "m_ctype.h"
#include "m_string.h"
#include "my_alloc.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_macros.h"
#include "my_sys.h"
#include "typelib.h"

Macros

#define is_field_separator(X)   ((X) == ',' || (X) == '=')
 

Functions

int find_type_or_exit (const char *x, TYPELIB *typelib, const char *option)
 
int find_type (const char *x, const TYPELIB *typelib, uint flags)
 Search after a string in a list of strings. More...
 
const char * get_type (TYPELIB *typelib, uint nr)
 Get type. More...
 
uint64_t find_typeset (const char *x, TYPELIB *lib, int *err)
 Create an integer value to represent the supplied comma-separated string where each string in the TYPELIB denotes a bit position. More...
 
TYPELIBcopy_typelib (MEM_ROOT *root, TYPELIB *from)
 Create a copy of a specified TYPELIB structure. More...
 
static int parse_name (const TYPELIB *lib, const char **strpos, const char *end)
 Parse a TYPELIB name from the buffer. More...
 
uint64_t find_set_from_flags (const TYPELIB *lib, int default_name, uint64_t cur_set, uint64_t default_set, const char *str, uint length, const char **err_pos, uint *err_len)
 Parse and apply a set of flag assingments. More...
 

Variables

static const char * on_off_default_names [] = {"off", "on", "default", nullptr}
 
static TYPELIB on_off_default_typelib
 

Detailed Description

Functions to handle typelib.

Macro Definition Documentation

◆ is_field_separator

#define is_field_separator (   X)    ((X) == ',' || (X) == '=')

Function Documentation

◆ copy_typelib()

TYPELIB * copy_typelib ( MEM_ROOT root,
TYPELIB from 
)

Create a copy of a specified TYPELIB structure.

Parameters
rootpointer to a MEM_ROOT object for allocations
frompointer to a source TYPELIB structure
Return values
pointerto the new TYPELIB structure on successful copy
NULLotherwise

◆ find_set_from_flags()

uint64_t find_set_from_flags ( const TYPELIB lib,
int  default_name,
uint64_t  cur_set,
uint64_t  default_set,
const char *  str,
uint  length,
const char **  err_pos,
uint err_len 
)

Parse and apply a set of flag assingments.

Parameters
libFlag names
default_nameNumber of "default" in the typelib
cur_setCurrent set of flags (start from this state)
default_setDefault set of flags (use this for assign-default keyword and flag=default assignments)
strString to be parsed
lengthLength of the string
err_posOUT If error, set to point to start of wrong set string NULL on success
err_lenOUT If error, set to the length of wrong set string

Parse a set of flag assignments, that is, parse a string in form:

param_name1=value1,param_name2=value2,...

where the names are specified in the TYPELIB, and each value can be either 'on','off', or 'default'. Setting the same name twice is not allowed.

Besides param=val assignments, we support the "default" keyword (keyword default_name in the typelib). It can be used one time, if specified it causes us to build the new set over the default_set rather than cur_set value.

Note
it's not charset aware
Return values
Parsedset value if (*errpos == NULL), otherwise undefined

◆ find_type()

int find_type ( const char *  x,
const TYPELIB typelib,
uint  flags 
)

Search after a string in a list of strings.

Endspace in x is not compared.

Parameters
xString to find
typelibTYPELIB (struct of pointer to values + count)
flagsflags to tune behaviour: a combination of FIND_TYPE_NO_PREFIX FIND_TYPE_ALLOW_NUMBER FIND_TYPE_COMMA_TERM. FIND_TYPE_NO_OVERWRITE can be passed but is redundant (is always implicitly on).
Return values
-1Too many matching values
0No matching value
>0Offset+1 in typelib for matched string

◆ find_type_or_exit()

int find_type_or_exit ( const char *  x,
TYPELIB typelib,
const char *  option 
)

◆ find_typeset()

uint64_t find_typeset ( const char *  x,
TYPELIB lib,
int *  err 
)

Create an integer value to represent the supplied comma-separated string where each string in the TYPELIB denotes a bit position.

Parameters
xstring to decompose
libTYPELIB (struct of pointer to values + count)
errindex (not char position) of string element which was not found or 0 if there was no error
Return values
ainteger representation of the supplied string

◆ get_type()

const char * get_type ( TYPELIB typelib,
uint  nr 
)

Get type.

Note
first type is 0

◆ parse_name()

static int parse_name ( const TYPELIB lib,
const char **  strpos,
const char *  end 
)
static

Parse a TYPELIB name from the buffer.

Parameters
libSet of names to scan for.
strposINOUT Start of the buffer (updated to point to the next character after the name)
endEnd of the buffer
Note
The buffer is assumed to contain one of the names specified in the TYPELIB, followed by comma, '=', or end of the buffer.
Return values
-1Too many matching values
0No matching name
>0Offset+1 in typelib for matched name

Variable Documentation

◆ on_off_default_names

const char* on_off_default_names[] = {"off", "on", "default", nullptr}
static

◆ on_off_default_typelib

TYPELIB on_off_default_typelib
static
Initial value:
= {
nullptr}
static const char * on_off_default_names[]
Definition: typelib.cc:227
#define array_elements(A)
Definition: validate_password_imp.cc:45