32 lines
1003 B
C
32 lines
1003 B
C
#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];
|
|
} |