|
libft
|
String ↔ number conversion and formatting. More...
Files | |
| file | ft_convert.h |
| Numeric conversion utility functions. | |
| file | ft_number_conversion.c |
| Number-to-string and string-to-number conversion functions. | |
Functions | |
| long long | ft_atoi (const char *str) |
| Converts a string to a signed integer. | |
| long long | ft_atoll (const char *str) |
Converts a string to a long long value. | |
| static size_t | ft_baselen (unsigned long long n, int base) |
| Calculates the number of digits to represent a value in a given base. | |
| static bool | ft_check_overflow (long long num, char digit, int sign) |
| Checks for overflow when converting a string to a long long integer. | |
| char * | ft_itoa (int n) |
| Converts an integer to a string. | |
| char * | ft_itoa_base (unsigned long long n, int base, int uppercase) |
| Converts an unsigned integer to a string in a given base. | |
| char * | ft_utoa (unsigned long long n) |
| Converts an unsigned long long to a decimal string. | |
String ↔ number conversion and formatting.
This group provides functions to convert strings to numbers (like ft_atoi and ft_atoll) with overflow detection, and to format unsigned integers into strings, optionally in base 2 to 16.
This group includes:
| long long ft_atoi | ( | const char * | str | ) |
#include <include/ft_convert.h>
Converts a string to a signed integer.
Converts the null-terminated string str to a long long value. Handles optional leading whitespace, sign, and overflow.
| str | The string to convert. |
ATOI_ERROR on overflow.| long long ft_atoll | ( | const char * | str | ) |
#include <include/ft_convert.h>
Converts a string to a long long value.
Similar to ft_atoi, but does not cast to int and returns a full long long result. Handles whitespace, signs, and overflow.
| str | The string to convert. |
ATOI_ERROR on overflow.
|
static |
#include <srcs/convert/ft_number_conversion.c>
Calculates the number of digits to represent a value in a given base.
Computes how many characters are needed to express n in base base. Used internally by ft_itoa_base.
| n | The number to analyze. |
| base | The numerical base (2–16). |
n.
|
static |
#include <srcs/convert/ft_number_conversion.c>
Checks for overflow when converting a string to a long long integer.
Evaluates whether appending a digit to num would cause it to overflow a signed 32-bit integer, taking into account the current sign.
| num | The current number being built. |
| digit | The current character digit to append. |
| sign | The number sign (1 for positive, -1 for negative). |
| char * ft_itoa | ( | int | n | ) |
#include <include/ft_convert.h>
Converts an integer to a string.
Allocates and returns a new string representing the integer n. Handles negative numbers and returns NULL if allocation fails.
| n | The integer to convert. |
n, or NULL on failure. | char * ft_itoa_base | ( | unsigned long long | n, |
| int | base, | ||
| int | uppercase | ||
| ) |
#include <include/ft_convert.h>
Converts an unsigned integer to a string in a given base.
Converts the unsigned number n to a string in base base (2–16). Uses lowercase or uppercase digits based on uppercase.
| n | The number to convert. |
| base | The base for conversion (2–16). |
| uppercase | If 1, use uppercase letters for bases > 10. |
| char * ft_utoa | ( | unsigned long long | n | ) |
#include <include/ft_convert.h>
Converts an unsigned long long to a decimal string.
Converts the value n to its decimal string representation. A null-terminated string is returned. The caller must free it.
| n | The number to convert. |