summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC/langinfo.cpp
blob: c2e830c8d86fe24fa5e0da2f1567246309d9743f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * Copyright (c) 2021, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <langinfo.h>

// Values taken from glibc's en_US locale files.
static const char* __nl_langinfo(nl_item item)
{
    switch (item) {
    case CODESET:
        return "UTF-8";
    case D_T_FMT:
        return "%a %d %b %Y %r %Z";
    case D_FMT:
        return "%m/%d/%Y";
    case T_FMT:
        return "%r";
    case T_FMT_AMPM:
        return "%I:%M:%S %p";
    case AM_STR:
        return "AM";
    case PM_STR:
        return "PM";
    case DAY_1:
        return "Sunday";
    case DAY_2:
        return "Monday";
    case DAY_3:
        return "Tuesday";
    case DAY_4:
        return "Wednesday";
    case DAY_5:
        return "Thursday";
    case DAY_6:
        return "Friday";
    case DAY_7:
        return "Saturday";
    case ABDAY_1:
        return "Sun";
    case ABDAY_2:
        return "Mon";
    case ABDAY_3:
        return "Tue";
    case ABDAY_4:
        return "Wed";
    case ABDAY_5:
        return "Thu";
    case ABDAY_6:
        return "Fri";
    case ABDAY_7:
        return "Sat";
    case MON_1:
        return "January";
    case MON_2:
        return "February";
    case MON_3:
        return "March";
    case MON_4:
        return "April";
    case MON_5:
        return "May";
    case MON_6:
        return "June";
    case MON_7:
        return "July";
    case MON_8:
        return "August";
    case MON_9:
        return "September";
    case MON_10:
        return "October";
    case MON_11:
        return "November";
    case MON_12:
        return "December";
    case ABMON_1:
        return "Jan";
    case ABMON_2:
        return "Feb";
    case ABMON_3:
        return "Mar";
    case ABMON_4:
        return "Apr";
    case ABMON_5:
        return "May";
    case ABMON_6:
        return "Jun";
    case ABMON_7:
        return "Jul";
    case ABMON_8:
        return "Aug";
    case ABMON_9:
        return "Sep";
    case ABMON_10:
        return "Oct";
    case ABMON_11:
        return "Nov";
    case ABMON_12:
        return "Dec";
    case RADIXCHAR:
        return ".";
    case THOUSEP:
        return ",";
    case YESEXPR:
        return "^[+1yY]";
    case NOEXPR:
        return "^[-0nN]";
    // en_US does not have ERA.
    case ERA:
    case ERA_D_FMT:
    case ERA_D_T_FMT:
    case ERA_T_FMT:
    // en_US also doesn't have special digit symbols.
    case ALT_DIGITS:
    // Invalid values also return an empty string.
    default:
        return "";
    }
}

extern "C" {

char* nl_langinfo(nl_item item)
{
    // POSIX states that returned strings should not be modified,
    // so this cast is probably fine.
    return const_cast<char*>(__nl_langinfo(item));
}
}