File tree Expand file tree Collapse file tree 15 files changed +194
-10
lines changed Expand file tree Collapse file tree 15 files changed +194
-10
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ set(TARGET_LIBC_ENTRYPOINTS
12
12
libc.src.ctype.isspace
13
13
libc.src.ctype.isupper
14
14
libc.src.ctype.isxdigit
15
+ libc.src.ctype.tolower
16
+ libc.src.ctype.toupper
15
17
16
18
# errno.h entrypoints
17
19
libc.src.errno.__errno_location
Original file line number Diff line number Diff line change @@ -100,6 +100,8 @@ def CTypeAPI : PublicAPI<"ctype.h"> {
100
100
"isspace",
101
101
"isupper",
102
102
"isxdigit",
103
+ "tolower",
104
+ "toupper",
103
105
];
104
106
}
105
107
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ set(TARGET_LIBC_ENTRYPOINTS
15
15
libc.src.ctype.isspace
16
16
libc.src.ctype.isupper
17
17
libc.src.ctype.isxdigit
18
+ libc.src.ctype.tolower
19
+ libc.src.ctype.toupper
18
20
19
21
# errno.h entrypoints
20
22
libc.src.errno.__errno_location
Original file line number Diff line number Diff line change @@ -106,6 +106,16 @@ def StdC : StandardSpec<"stdc"> {
106
106
RetValSpec<IntType>,
107
107
[ArgSpec<IntType>]
108
108
>,
109
+ FunctionSpec<
110
+ "tolower",
111
+ RetValSpec<IntType>,
112
+ [ArgSpec<IntType>]
113
+ >,
114
+ FunctionSpec<
115
+ "toupper",
116
+ RetValSpec<IntType>,
117
+ [ArgSpec<IntType>]
118
+ >,
109
119
]
110
120
>;
111
121
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ add_entrypoint_object(
66
66
islower.cpp
67
67
HDRS
68
68
islower.h
69
+ DEPENDS
70
+ .ctype_utils
69
71
)
70
72
71
73
add_entrypoint_object(
@@ -100,6 +102,8 @@ add_entrypoint_object(
100
102
isupper.cpp
101
103
HDRS
102
104
isupper.h
105
+ DEPENDS
106
+ .ctype_utils
103
107
)
104
108
105
109
add_entrypoint_object(
@@ -111,3 +115,23 @@ add_entrypoint_object(
111
115
DEPENDS
112
116
.ctype_utils
113
117
)
118
+
119
+ add_entrypoint_object(
120
+ tolower
121
+ SRCS
122
+ tolower.cpp
123
+ HDRS
124
+ tolower.h
125
+ DEPENDS
126
+ .ctype_utils
127
+ )
128
+
129
+ add_entrypoint_object(
130
+ toupper
131
+ SRCS
132
+ toupper.cpp
133
+ HDRS
134
+ toupper.h
135
+ DEPENDS
136
+ .ctype_utils
137
+ )
Original file line number Diff line number Diff line change @@ -18,14 +18,18 @@ namespace internal {
18
18
// of a function call by inlining them.
19
19
// ------------------------------------------------------
20
20
21
- static inline int isdigit(unsigned ch) { return (ch - '0') < 10; }
22
-
23
21
static inline int isalpha(unsigned ch) { return (ch | 32) - 'a' < 26; }
24
22
23
+ static inline int isdigit(unsigned ch) { return (ch - '0') < 10; }
24
+
25
25
static inline int isalnum(unsigned ch) { return isalpha(ch) || isdigit(ch); }
26
26
27
27
static inline int isgraph(unsigned ch) { return 0x20 < ch && ch < 0x7f; }
28
28
29
+ static inline int islower(unsigned ch) { return (ch - 'a') < 26; }
30
+
31
+ static inline int isupper(unsigned ch) { return (ch - 'A') < 26; }
32
+
29
33
} // namespace internal
30
34
} // namespace __llvm_libc
31
35
Original file line number Diff line number Diff line change 7
7
//===----------------------------------------------------------------------===//
8
8
9
9
#include "src/ctype/islower.h"
10
+ #include "src/ctype/ctype_utils.h"
10
11
11
12
#include "src/__support/common.h"
12
13
13
14
namespace __llvm_libc {
14
15
15
16
// TODO: Currently restricted to default locale.
16
17
// These should be extended using locale information.
17
- int LLVM_LIBC_ENTRYPOINT(islower)(int c) {
18
- const unsigned ch = c;
19
- return (ch - 'a') < 26;
20
- }
18
+ int LLVM_LIBC_ENTRYPOINT(islower)(int c) { return internal::islower(c); }
21
19
22
20
} // namespace __llvm_libc
Original file line number Diff line number Diff line change 7
7
//===----------------------------------------------------------------------===//
8
8
9
9
#include "src/ctype/isupper.h"
10
+ #include "src/ctype/ctype_utils.h"
10
11
11
12
#include "src/__support/common.h"
12
13
13
14
namespace __llvm_libc {
14
15
15
16
// TODO: Currently restricted to default locale.
16
17
// These should be extended using locale information.
17
- int LLVM_LIBC_ENTRYPOINT(isupper)(int c) {
18
- const unsigned ch = c;
19
- return (ch - 'A') < 26;
20
- }
18
+ int LLVM_LIBC_ENTRYPOINT(isupper)(int c) { return internal::isupper(c); }
21
19
22
20
} // namespace __llvm_libc
Original file line number Diff line number Diff line change
1
+ //===-- Implementation of tolower------------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #include "src/ctype/tolower.h"
10
+ #include "src/ctype/ctype_utils.h"
11
+
12
+ #include "src/__support/common.h"
13
+
14
+ namespace __llvm_libc {
15
+
16
+ // TODO: Currently restricted to default locale.
17
+ // These should be extended using locale information.
18
+ int LLVM_LIBC_ENTRYPOINT(tolower)(int c) {
19
+ if (internal::isupper(c))
20
+ return c + 'a' - 'A';
21
+ return c;
22
+ }
23
+
24
+ } // namespace __llvm_libc
Original file line number Diff line number Diff line change
1
+ //===-- Implementation header for tolower -------------------------*-C++-*-===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #ifndef LLVM_LIBC_SRC_CTYPE_TOLOWER_H
10
+ #define LLVM_LIBC_SRC_CTYPE_TOLOWER_H
11
+
12
+ namespace __llvm_libc {
13
+
14
+ int tolower(int c);
15
+
16
+ } // namespace __llvm_libc
17
+
18
+ #endif // LLVM_LIBC_SRC_CTYPE_TOLOWER_H
You can’t perform that action at this time.
0 commit comments