File tree Expand file tree Collapse file tree 12 files changed +190
-1
lines changed Expand file tree Collapse file tree 12 files changed +190
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ set(TARGET_LIBC_ENTRYPOINTS
2
2
# ctype.h entrypoints
3
3
libc.src.ctype.isalnum
4
4
libc.src.ctype.isalpha
5
+ libc.src.ctype.isascii
5
6
libc.src.ctype.isblank
6
7
libc.src.ctype.iscntrl
7
8
libc.src.ctype.isdigit
@@ -12,6 +13,7 @@ set(TARGET_LIBC_ENTRYPOINTS
12
13
libc.src.ctype.isspace
13
14
libc.src.ctype.isupper
14
15
libc.src.ctype.isxdigit
16
+ libc.src.ctype.toascii
15
17
libc.src.ctype.tolower
16
18
libc.src.ctype.toupper
17
19
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ set(TARGET_LIBC_ENTRYPOINTS
5
5
# ctype.h entrypoints
6
6
libc.src.ctype.isalnum
7
7
libc.src.ctype.isalpha
8
+ libc.src.ctype.isascii
8
9
libc.src.ctype.isblank
9
10
libc.src.ctype.iscntrl
10
11
libc.src.ctype.isdigit
@@ -15,6 +16,7 @@ set(TARGET_LIBC_ENTRYPOINTS
15
16
libc.src.ctype.isspace
16
17
libc.src.ctype.isupper
17
18
libc.src.ctype.isxdigit
19
+ libc.src.ctype.toascii
18
20
libc.src.ctype.tolower
19
21
libc.src.ctype.toupper
20
22
Original file line number Diff line number Diff line change 1
1
def GnuExtensions : StandardSpec<"GNUExtensions"> {
2
+ HeaderSpec CType = HeaderSpec<
3
+ "ctype.h",
4
+ [], // Macros
5
+ [], // Types
6
+ [], // Enumerations
7
+ [
8
+ FunctionSpec<
9
+ "toascii",
10
+ RetValSpec<IntType>,
11
+ [ArgSpec<IntType>]
12
+ >,
13
+ ]
14
+ >;
15
+
2
16
HeaderSpec Math = HeaderSpec<
3
17
"math.h",
4
18
[], // Macros
@@ -27,7 +41,10 @@ def GnuExtensions : StandardSpec<"GNUExtensions"> {
27
41
]
28
42
>;
29
43
44
+
30
45
let Headers = [
31
- Math, String,
46
+ CType,
47
+ Math,
48
+ String,
32
49
];
33
50
}
Original file line number Diff line number Diff line change @@ -235,7 +235,22 @@ def POSIX : StandardSpec<"POSIX"> {
235
235
]
236
236
>;
237
237
238
+ HeaderSpec CType = HeaderSpec<
239
+ "ctype.h",
240
+ [], // Macros
241
+ [], // Types
242
+ [], // Enumerations
243
+ [
244
+ FunctionSpec<
245
+ "isascii",
246
+ RetValSpec<IntType>,
247
+ [ArgSpec<IntType>]
248
+ >,
249
+ ]
250
+ >;
251
+
238
252
let Headers = [
253
+ CType,
239
254
Errno,
240
255
SysMMan,
241
256
Signal,
Original file line number Diff line number Diff line change @@ -24,6 +24,14 @@ add_entrypoint_object(
24
24
.ctype_utils
25
25
)
26
26
27
+ add_entrypoint_object (
28
+ isascii
29
+ SRCS
30
+ isascii.cpp
31
+ HDRS
32
+ isascii.h
33
+ )
34
+
27
35
add_entrypoint_object (
28
36
isblank
29
37
SRCS
@@ -126,6 +134,14 @@ add_entrypoint_object(
126
134
.ctype_utils
127
135
)
128
136
137
+ add_entrypoint_object (
138
+ toascii
139
+ SRCS
140
+ toascii.cpp
141
+ HDRS
142
+ toascii.h
143
+ )
144
+
129
145
add_entrypoint_object (
130
146
toupper
131
147
SRCS
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation of isascii------------------------------------------===//
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/isascii.h"
10
+
11
+ #include " src/__support/common.h"
12
+
13
+ namespace __llvm_libc {
14
+
15
+ LLVM_LIBC_FUNCTION (int , isascii, (int c)) { return (c & (~0x7f )) == 0 ; }
16
+
17
+ } // namespace __llvm_libc
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation header for isascii -------------------------*-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_ISASCII_H
10
+ #define LLVM_LIBC_SRC_CTYPE_ISASCII_H
11
+
12
+ namespace __llvm_libc {
13
+
14
+ int isascii (int c);
15
+
16
+ } // namespace __llvm_libc
17
+
18
+ #endif // LLVM_LIBC_SRC_CTYPE_ISASCII_H
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation of toascii------------------------------------------===//
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/toascii.h"
10
+
11
+ #include " src/__support/common.h"
12
+
13
+ namespace __llvm_libc {
14
+
15
+ LLVM_LIBC_FUNCTION (int , toascii, (int c)) { return (c & 0x7f ); }
16
+
17
+ } // namespace __llvm_libc
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation header for toascii -------------------------*-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_TOASCII_H
10
+ #define LLVM_LIBC_SRC_CTYPE_TOASCII_H
11
+
12
+ namespace __llvm_libc {
13
+
14
+ int toascii (int c);
15
+
16
+ } // namespace __llvm_libc
17
+
18
+ #endif // LLVM_LIBC_SRC_CTYPE_TOASCII_H
Original file line number Diff line number Diff line change @@ -20,6 +20,16 @@ add_libc_unittest(
20
20
libc.src.ctype.isalpha
21
21
)
22
22
23
+ add_libc_unittest (
24
+ isascii
25
+ SUITE
26
+ libc_ctype_unittests
27
+ SRCS
28
+ isascii_test.cpp
29
+ DEPENDS
30
+ libc.src.ctype.isascii
31
+ )
32
+
23
33
add_libc_unittest (
24
34
isblank
25
35
SUITE
@@ -120,6 +130,16 @@ add_libc_unittest(
120
130
libc.src.ctype.isxdigit
121
131
)
122
132
133
+ add_libc_unittest (
134
+ toascii
135
+ SUITE
136
+ libc_ctype_unittests
137
+ SRCS
138
+ toascii_test.cpp
139
+ DEPENDS
140
+ libc.src.ctype.toascii
141
+ )
142
+
123
143
add_libc_unittest (
124
144
tolower
125
145
SUITE
Original file line number Diff line number Diff line change
1
+ // ===-- Unittests for isascii----------------------------------------------===//
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/isascii.h"
10
+
11
+ #include " utils/UnitTest/Test.h"
12
+
13
+ TEST (IsAscii, DefaultLocale) {
14
+ // Loops through all characters, verifying that ascii characters
15
+ // (which are all 7 bit unsigned integers)
16
+ // return a non-zero integer and everything else returns zero.
17
+ for (int ch = 0 ; ch < 255 ; ++ch) {
18
+ if (ch <= 0x7f )
19
+ EXPECT_NE (__llvm_libc::isascii (ch), 0 );
20
+ else
21
+ EXPECT_EQ (__llvm_libc::isascii (ch), 0 );
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ // ===-- Unittests for toascii----------------------------------------------===//
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/toascii.h"
10
+
11
+ #include " utils/UnitTest/Test.h"
12
+
13
+ TEST (ToAscii, DefaultLocale) {
14
+ // Loops through all characters, verifying that ascii characters
15
+ // (which are all 7 bit unsigned integers)
16
+ // return themself, and that all other characters return themself
17
+ // mod 128 (which is equivalent to & 0x7f)
18
+ for (int ch = 0 ; ch < 255 ; ++ch) {
19
+ if (ch <= 0x7f )
20
+ EXPECT_EQ (__llvm_libc::toascii (ch), ch);
21
+ else
22
+ EXPECT_EQ (__llvm_libc::toascii (ch), ch & 0x7f );
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments