diff --git a/Makefile b/Makefile index f005c55..e003bc0 100644 --- a/Makefile +++ b/Makefile @@ -134,7 +134,8 @@ SRCS = ft_memset.c \ ft_round.c \ ft_free_tab.c \ \ - ft_arrint.c + ft_arrint.c \ + ft_superscript.c ODIR = ./builds diff --git a/includes/libft.h b/includes/libft.h index f80a35c..93c4990 100644 --- a/includes/libft.h +++ b/includes/libft.h @@ -137,5 +137,6 @@ int ft_sqrt(int i); void ft_free_tab(char **tab); int ft_arrint(int *intarr, int comp, size_t size); +const char *ft_superscript(char c); #endif diff --git a/srcs/ft_superscript.c b/srcs/ft_superscript.c new file mode 100644 index 0000000..67303e5 --- /dev/null +++ b/srcs/ft_superscript.c @@ -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]; +} \ No newline at end of file