MySQL  8.0.27
Source Code Documentation
integer_digits.h File Reference

This file contains utilities for accessing digits of integers, and for converting them to strings. More...

#include <assert.h>
#include <algorithm>
#include <limits>
#include <type_traits>

Go to the source code of this file.

Classes

class  TwoDigitWriter
 Helper class for write_two_digits(), which creates a table that maps every integer from 0 to 99 to a two-char sequence that represents its two base 10 digits. More...
 
struct  DigitCounter< T, MinDigits, MaxDigits, typename >
 Functor that calculates the number of digits in an unsigned integer using binary search. More...
 
struct  DigitCounter< T, MinDigits, MaxDigits, typename std::enable_if< MinDigits==MaxDigits >::type >
 Counts the number of digits for the trivial case where the known minimum number of digits is equal to the known maximum number of digits. More...
 

Functions

char * write_two_digits (int value, char *to)
 Writes an integer, which is between 0 (inclusive) and 100 (exclusive), to a string in base 10. More...
 
template<typename T >
constexpr int count_digits (T x)
 Counts the number of base 10 digits in an unsigned integer. More...
 
template<typename T >
char * write_digits (T number, int digits, char *to)
 Writes an unsigned integer of the specified length to a string. More...
 

Detailed Description

This file contains utilities for accessing digits of integers, and for converting them to strings.

Function Documentation

◆ count_digits()

template<typename T >
constexpr int count_digits ( x)
constexpr

Counts the number of base 10 digits in an unsigned integer.

Parameters
xthe number whose digits to count
Returns
the number of digits in the number

◆ write_digits()

template<typename T >
char* write_digits ( number,
int  digits,
char *  to 
)
inline

Writes an unsigned integer of the specified length to a string.

The string is not zero-terminated.

Parameters
numberthe number to write
digitsthe number of digits to write (the number is zero-padded if it is shorter)
[in,out]tothe destination string
Returns
pointer to the character just after the last digit

◆ write_two_digits()

char* write_two_digits ( int  value,
char *  to 
)
inline

Writes an integer, which is between 0 (inclusive) and 100 (exclusive), to a string in base 10.

Always writes two digits, zero-padded if necessary. The string is not zero-terminated.

Parameters
valuethe number to write
[in,out]tothe destination string
Returns
pointer to the character just after the last digit