Compare commits

..

1 Commits

Author SHA1 Message Date
hugogogo
3cf0b6ecb9 adding superscript char 2026-05-07 14:47:18 +02:00
3 changed files with 35 additions and 1 deletions

View File

@@ -134,7 +134,8 @@ SRCS = ft_memset.c \
ft_round.c \ ft_round.c \
ft_free_tab.c \ ft_free_tab.c \
\ \
ft_arrint.c ft_arrint.c \
ft_superscript.c
ODIR = ./builds ODIR = ./builds

View File

@@ -137,5 +137,6 @@ int ft_sqrt(int i);
void ft_free_tab(char **tab); void ft_free_tab(char **tab);
int ft_arrint(int *intarr, int comp, size_t size); int ft_arrint(int *intarr, int comp, size_t size);
const char *ft_superscript(char c);
#endif #endif

32
srcs/ft_superscript.c Normal file
View File

@@ -0,0 +1,32 @@
#include "libft.h"
/**
* Converts a single digit character (0-9) to its superscript string representation.
*
* @param c The digit character (e.g., '0', '1', ..., '9').
* @return A static string containing the superscript representation of the digit.
* Returns NULL if the input is not a digit.
*/
const char *ft_superscript(char c)
{
// Array of superscript digit strings (UTF-8 literals)
static const char *superscript_digits[10] = {
"\xE2\x81\xB0", // ⁰ (U+2070)
"\xC2\xB9", // ¹ (U+00B9)
"\xC2\xB2", // ² (U+00B2)
"\xC2\xB3", // ³ (U+00B3)
"\xE2\x81\xB4", // ⁴ (U+2074)
"\xE2\x81\xB5", // ⁵ (U+2075)
"\xE2\x81\xB6", // ⁶ (U+2076)
"\xE2\x81\xB7", // ⁷ (U+2077)
"\xE2\x81\xB8", // ⁸ (U+2078)
"\xE2\x81\xB9" // ⁹ (U+2079)
};
if (c < '0' || c > '9')
{
return NULL; // Not a digit
}
int digit = c - '0';
return superscript_digits[digit];
}