-
Notifications
You must be signed in to change notification settings - Fork 15k
[libc] add wctype.h header #149202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[libc] add wctype.h header #149202
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
77f1c39
[libc] add wctype.h header
Prabhuk f2596a6
Format changes
Prabhuk f61809d
Add public header wctype
Prabhuk e310c0b
Fix copy paste naming bugs.
Prabhuk 87f8bcf
Add iswalpha tests
Prabhuk c8ea095
format
Prabhuk 948068b
format 2
Prabhuk 4ef993b
Add entrypoints for other platforms requested in review.
Prabhuk 230c273
Add EOF newline
Prabhuk 62604e7
Merge branch 'main' into wctype
Prabhuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ set(TARGET_PUBLIC_HEADERS | |
libc.include.time | ||
libc.include.uchar | ||
libc.include.wchar | ||
libc.include.wctype | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ set(TARGET_PUBLIC_HEADERS | |
libc.include.time | ||
libc.include.uchar | ||
libc.include.wchar | ||
libc.include.wctype | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ set(TARGET_PUBLIC_HEADERS | |
libc.include.stdlib | ||
libc.include.string | ||
libc.include.strings | ||
libc.include.wctype | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,5 @@ set(TARGET_PUBLIC_HEADERS | |
libc.include.uchar | ||
libc.include.unistd | ||
libc.include.wchar | ||
libc.include.wctype | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,5 @@ set(TARGET_PUBLIC_HEADERS | |
libc.include.uchar | ||
libc.include.unistd | ||
libc.include.wchar | ||
libc.include.wctype | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,5 @@ set(TARGET_PUBLIC_HEADERS | |
libc.include.uchar | ||
libc.include.unistd | ||
libc.include.wchar | ||
libc.include.wctype | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ set(TARGET_PUBLIC_HEADERS | |
libc.include.fenv | ||
libc.include.math | ||
libc.include.unistd | ||
libc.include.wctype | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
header: wctype.h | ||
types: | ||
- type_name: wint_t | ||
functions: | ||
- name: iswalpha | ||
standards: | ||
- stdc | ||
return_type: int | ||
arguments: | ||
- type: wint_t |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
add_entrypoint_object( | ||
iswalpha | ||
SRCS | ||
iswalpha.cpp | ||
HDRS | ||
iswalpha.h | ||
DEPENDS | ||
libc.src.__support.wctype_utils | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//===-- Implementation of iswalpha ----------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/wctype/iswalpha.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/wctype_utils.h" | ||
|
||
#include "hdr/types/wint_t.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(bool, iswalpha, (wint_t c)) { return internal::iswalpha(c); } | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//===-- Implementation header for iswalpha ----------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_WCTYPE_ISWALPHA_H | ||
#define LLVM_LIBC_SRC_WCTYPE_ISWALPHA_H | ||
|
||
#include "hdr/types/wint_t.h" | ||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
bool iswalpha(wint_t c); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_WCTYPE_ISWALPHA_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
add_custom_target(libc_wctype_unittests) | ||
|
||
add_libc_test( | ||
iswalpha_test | ||
SUITE | ||
libc_wctype_unittests | ||
SRCS | ||
iswalpha_test.cpp | ||
DEPENDS | ||
libc.src.wctype.iswalpha | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//===-- Unittests for iswalpha --------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/__support/CPP/span.h" | ||
#include "src/wctype/iswalpha.h" | ||
|
||
#include "test/UnitTest/LibcTest.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
namespace { | ||
|
||
// TODO: Merge the wctype tests using this framework. | ||
constexpr char WALPHA_ARRAY[] = { | ||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', | ||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', | ||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', | ||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', | ||
}; | ||
|
||
bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { | ||
for (size_t i = 0; i < arr.size(); ++i) | ||
if (static_cast<int>(arr[i]) == ch) | ||
return true; | ||
return false; | ||
} | ||
|
||
} // namespace | ||
|
||
TEST(LlvmLibciswalpha, SimpleTest) { | ||
EXPECT_TRUE(LIBC_NAMESPACE::iswalpha('a')); | ||
EXPECT_TRUE(LIBC_NAMESPACE::iswalpha('B')); | ||
|
||
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('3')); | ||
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(' ')); | ||
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('?')); | ||
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha('\0')); | ||
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(-1)); | ||
} | ||
|
||
TEST(LlvmLibciswalpha, DefaultLocale) { | ||
// Loops through all characters, verifying that letters return | ||
// true and everything else returns false. | ||
for (int ch = -255; ch < 255; ++ch) { | ||
if (in_span(ch, WALPHA_ARRAY)) | ||
EXPECT_TRUE(LIBC_NAMESPACE::iswalpha(ch)); | ||
else | ||
EXPECT_FALSE(LIBC_NAMESPACE::iswalpha(ch)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.