From bd5969fc876a10b18613302db7087ef3c40f18e1 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:00 -0500 Subject: lib: Add mlibc Signed-off-by: Ian Moffett --- lib/mlibc/options/internal/generic/locale.cpp | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 lib/mlibc/options/internal/generic/locale.cpp (limited to 'lib/mlibc/options/internal/generic/locale.cpp') diff --git a/lib/mlibc/options/internal/generic/locale.cpp b/lib/mlibc/options/internal/generic/locale.cpp new file mode 100644 index 0000000..7ba040f --- /dev/null +++ b/lib/mlibc/options/internal/generic/locale.cpp @@ -0,0 +1,87 @@ +#include +#include +#include + +namespace mlibc { + +char *nl_langinfo(nl_item item) { + if(item == CODESET) { + return const_cast("UTF-8"); + } else if(item >= ABMON_1 && item <= ABMON_12) { + switch(item) { + case ABMON_1: return const_cast("Jan"); + case ABMON_2: return const_cast("Feb"); + case ABMON_3: return const_cast("Mar"); + case ABMON_4: return const_cast("Apr"); + case ABMON_5: return const_cast("May"); + case ABMON_6: return const_cast("Jun"); + case ABMON_7: return const_cast("Jul"); + case ABMON_8: return const_cast("Aug"); + case ABMON_9: return const_cast("Sep"); + case ABMON_10: return const_cast("Oct"); + case ABMON_11: return const_cast("Nov"); + case ABMON_12: return const_cast("Dec"); + default: + __ensure(!"ABMON_* constants don't seem to be contiguous!"); + __builtin_unreachable(); + } + } else if(item >= MON_1 && item <= MON_12) { + switch(item) { + case MON_1: return const_cast("January"); + case MON_2: return const_cast("Feburary"); + case MON_3: return const_cast("March"); + case MON_4: return const_cast("April"); + case MON_5: return const_cast("May"); + case MON_6: return const_cast("June"); + case MON_7: return const_cast("July"); + case MON_8: return const_cast("August"); + case MON_9: return const_cast("September"); + case MON_10: return const_cast("October"); + case MON_11: return const_cast("November"); + case MON_12: return const_cast("December"); + default: + __ensure(!"MON_* constants don't seem to be contiguous!"); + __builtin_unreachable(); + } + } else if(item == AM_STR) { + return const_cast("AM"); + } else if(item == PM_STR) { + return const_cast("PM"); + } else if(item >= DAY_1 && item <= DAY_7) { + switch(item) { + case DAY_1: return const_cast("Sunday"); + case DAY_2: return const_cast("Monday"); + case DAY_3: return const_cast("Tuesday"); + case DAY_4: return const_cast("Wednesday"); + case DAY_5: return const_cast("Thursday"); + case DAY_6: return const_cast("Friday"); + case DAY_7: return const_cast("Saturday"); + default: + __ensure(!"DAY_* constants don't seem to be contiguous!"); + __builtin_unreachable(); + } + } else if(item >= ABDAY_1 && item <= ABDAY_7) { + switch(item) { + case ABDAY_1: return const_cast("Sun"); + case ABDAY_2: return const_cast("Mon"); + case ABDAY_3: return const_cast("Tue"); + case ABDAY_4: return const_cast("Wed"); + case ABDAY_5: return const_cast("Thu"); + case ABDAY_6: return const_cast("Fri"); + case ABDAY_7: return const_cast("Sat"); + default: + __ensure(!"ABDAY_* constants don't seem to be contiguous!"); + __builtin_unreachable(); + } + }else if(item == D_FMT) { + return const_cast("%m/%d/%y"); + }else if(item == T_FMT) { + return const_cast("%H:%M:%S"); + }else{ + mlibc::infoLogger() << "mlibc: nl_langinfo item " + << item << " is not implemented properly" << frg::endlog; + return const_cast(""); + } +} + +} -- cgit v1.2.3