![]() |
MySQL 8.0.41
Source Code Documentation
|
#include <float.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include "decimal.h"
#include "lex_string.h"
#include "my_config.h"
#include "my_inttypes.h"
#include "my_macros.h"
Go to the source code of this file.
Macros | |
#define | NullS (char *)0 |
Definition of the null string (a null pointer of type char *), used in some of our string handling code. More... | |
#define | MAX_DECPT_FOR_F_FORMAT DBL_DIG |
#define | MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + std::max(5, MAX_DECPT_FOR_F_FORMAT)) |
#define | STRING_WITH_LEN(X) (X), ((sizeof(X) - 1)) |
Enumerations | |
enum | my_gcvt_arg_type { MY_GCVT_ARG_FLOAT , MY_GCVT_ARG_DOUBLE } |
Functions | |
char * | strmake (char *dst, const char *src, size_t length) |
char * | strcont (char *src, const char *set) |
char * | strxmov (char *dst, const char *src,...) |
char * | strxnmov (char *dst, size_t len, const char *src,...) |
static void | bchange (uchar *dst, size_t old_length, const uchar *src, size_t new_length, size_t tot_length) |
static const char * | strend (const char *s) |
static char * | strend (char *s) |
static const char * | strcend (const char *s, char c) |
static char * | strfill (char *s, size_t len, char fill) |
static char * | my_stpmov (char *dst, const char *src) |
static char * | my_stpnmov (char *dst, const char *src, size_t n) |
static char * | my_stpcpy (char *dst, const char *src) |
Copy a string from src to dst until (and including) terminating null byte. More... | |
static char * | my_stpncpy (char *dst, const char *src, size_t n) |
Copy fixed-size string from src to dst. More... | |
static longlong | my_strtoll (const char *nptr, char **endptr, int base) |
static ulonglong | my_strtoull (const char *nptr, char **endptr, int base) |
static char * | my_strtok_r (char *str, const char *delim, char **saveptr) |
static int | native_strcasecmp (const char *s1, const char *s2) |
static int | native_strncasecmp (const char *s1, const char *s2, size_t n) |
static int | is_prefix (const char *s, const char *t) |
double | my_strtod (const char *str, const char **end, int *error) |
Converts string to double (string does not have to be zero-terminated) More... | |
size_t | my_fcvt (double x, int precision, char *to, bool *error) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format. More... | |
size_t | my_fcvt_compact (double x, char *to, bool *error) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format. More... | |
size_t | my_gcvt (double x, my_gcvt_arg_type type, int width, char *to, bool *error) |
Converts a given floating point number to a zero-terminated string representation with a given field width using the 'e' format (aka scientific notation) or the 'f' one. More... | |
const char * | str2int (const char *src, int radix, long lower, long upper, long *val) |
longlong | my_strtoll10 (const char *nptr, const char **endptr, int *error) |
char * | ll2str (int64_t val, char *dst, int radix, bool upcase) |
Converts a 64-bit integer value to its character form and moves it to the destination buffer followed by a terminating NUL. More... | |
char * | longlong10_to_str (int64_t val, char *dst, int radix) |
Converts a 64-bit integer to its string representation in decimal notation. More... | |
char * | longlong2str (int64_t val, char *dst, int radix) |
static char * | llstr (longlong value, char *buff) |
static char * | ullstr (longlong value, char *buff) |
static const uchar * | skip_trailing_space (const uchar *ptr, size_t len) |
Skip trailing space (ASCII spaces only). More... | |
static void | human_readable_num_bytes (char *buf, int buf_len, double dbl_val) |
static void | lex_string_set (LEX_STRING *lex_str, char *c_str) |
static void | lex_cstring_set (LEX_CSTRING *lex_str, const char *c_str) |
Variables | |
void *(* | my_str_malloc )(size_t) |
void *(* | my_str_realloc )(void *, size_t) |
void(* | my_str_free )(void *) |
const char | _dig_vec_upper [] |
const char | _dig_vec_lower [] |
static constexpr int | FLOATING_POINT_BUFFER {311 + DECIMAL_NOT_SPECIFIED} |
#define MAX_DECPT_FOR_F_FORMAT DBL_DIG |
#define MY_GCVT_MAX_FIELD_WIDTH (DBL_DIG + 4 + std::max(5, MAX_DECPT_FOR_F_FORMAT)) |
#define NullS (char *)0 |
Definition of the null string (a null pointer of type char *), used in some of our string handling code.
New code should use nullptr instead.
enum my_gcvt_arg_type |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
char * ll2str | ( | int64_t | val, |
char * | dst, | ||
int | radix, | ||
bool | upcase | ||
) |
Converts a 64-bit integer value to its character form and moves it to the destination buffer followed by a terminating NUL.
If radix is -2..-36, val is taken to be SIGNED, if radix is 2..36, val is taken to be UNSIGNED. That is, val is signed if and only if radix is. All other radixes are treated as bad and nothing will be changed in this case.
For conversion to decimal representation (radix is -10 or 10) one should use the optimized longlong10_to_str() function instead.
val | the value to convert |
dst | the buffer where the string representation should be stored |
radix | radix of scale of notation |
upcase | true if we should use upper-case digits |
|
inlinestatic |
char * longlong10_to_str | ( | int64_t | val, |
char * | dst, | ||
int | radix | ||
) |
Converts a 64-bit integer to its string representation in decimal notation.
It is optimized for the normal case of radix 10/-10. It takes only the sign of radix parameter into account and not its absolute value.
val | the value to convert |
dst | the buffer where the string representation should be stored |
radix | 10 if val is unsigned, -10 if val is signed |
|
inline |
size_t my_fcvt | ( | double | x, |
int | precision, | ||
char * | to, | ||
bool * | error | ||
) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format.
This function is a wrapper around dtoa() to do the same as sprintf(to, "%-.*f", precision, x), though the conversion is usually more precise. The only difference is in handling [-,+]infinity and nan values, in which case we print '0\0' to the output string and indicate an overflow.
x | the input floating point number. |
precision | the number of digits after the decimal point. All properties of sprintf() apply:
|
to | pointer to the output buffer. The longest string which my_fcvt() can return is FLOATING_POINT_BUFFER bytes (including the terminating '\0'). |
error | if not NULL, points to a location where the status of conversion is stored upon return. false successful conversion true the input number is [-,+]infinity or nan. The output string in this case is always '0'. |
size_t my_fcvt_compact | ( | double | x, |
char * | to, | ||
bool * | error | ||
) |
Converts a given floating point number to a zero-terminated string representation using the 'f' format.
This function is a wrapper around dtoa() to do almost the same as sprintf(to, "%-.*f", precision, x), though the conversion is usually more precise. The only difference is in handling [-,+]infinity and nan values, in which case we print '0\0' to the output string and indicate an overflow.
The string always contains the minimum number of digits necessary to reproduce the same binary double value if the string is parsed back to a double value.
x | the input floating point number. |
to | pointer to the output buffer. The longest string which my_fcvt() can return is FLOATING_POINT_BUFFER bytes (including the terminating '\0'). |
error | if not NULL, points to a location where the status of conversion is stored upon return. false successful conversion true the input number is [-,+]infinity or nan. The output string in this case is always '0'. |
size_t my_gcvt | ( | double | x, |
my_gcvt_arg_type | type, | ||
int | width, | ||
char * | to, | ||
bool * | error | ||
) |
Converts a given floating point number to a zero-terminated string representation with a given field width using the 'e' format (aka scientific notation) or the 'f' one.
The format is chosen automatically to provide the most number of significant digits (and thus, precision) with a given field width. In many cases, the result is similar to that of sprintf(to, "%g", x) with a few notable differences:
x | the input floating point number. |
type | is either MY_GCVT_ARG_FLOAT or MY_GCVT_ARG_DOUBLE. Specifies the type of the input number (see notes above). |
width | field width in characters. The minimal field width to hold any number representation (albeit rounded) is 7 characters ("-Ne-NNN"). |
to | pointer to the output buffer. The result is always zero-terminated, and the longest returned string is thus 'width + 1' bytes. |
error | if not NULL, points to a location where the status of conversion is stored upon return. false successful conversion true the input number is [-,+]infinity or nan. The output string in this case is always '0'. |
my_gcvt(-9e-3, ..., 4, ...); my_gcvt(-9e-3, ..., 2, ...); my_gcvt(1.87e-3, ..., 4, ...); my_gcvt(55, ..., 1, ...);
We do our best to minimize such cases by:
|
inlinestatic |
Copy a string from src to dst until (and including) terminating null byte.
dst | Destination |
src | Source |
|
inlinestatic |
|
inlinestatic |
Copy fixed-size string from src to dst.
dst | Destination |
src | Source |
n | Maximum number of characters to copy. |
|
inlinestatic |
double my_strtod | ( | const char * | str, |
const char ** | end, | ||
int * | error | ||
) |
Converts string to double (string does not have to be zero-terminated)
This is a wrapper around dtoa's version of strtod().
str | input string |
end | address of a pointer to the first character after the input string. Upon return the pointer is set to point to the first rejected character. |
error | Upon return is set to EOVERFLOW in case of underflow or overflow. |
|
inlinestatic |
|
inlinestatic |
longlong my_strtoll10 | ( | const char * | nptr, |
const char ** | endptr, | ||
int * | error | ||
) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Skip trailing space (ASCII spaces only).
const char * str2int | ( | const char * | src, |
int | radix, | ||
long | lower, | ||
long | upper, | ||
long * | val | ||
) |
|
inlinestatic |
char * strcont | ( | char * | src, |
const char * | set | ||
) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
char * strmake | ( | char * | dst, |
const char * | src, | ||
size_t | length | ||
) |
char * strxmov | ( | char * | dst, |
const char * | src, | ||
... | |||
) |
char * strxnmov | ( | char * | dst, |
size_t | len, | ||
const char * | src, | ||
... | |||
) |
|
inlinestatic |
|
extern |
|
extern |
|
staticconstexpr |
|
extern |
|
extern |
|
extern |