Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions libc/src/__support/ctype_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace internal {
// as well as a way to support non-ASCII character encodings.

// Similarly, do not change these functions to use case ranges. e.g.
// bool islower(int ch) {
// bool islower(char ch) {
// switch(ch) {
// case 'a'...'z':
// return true;
Expand All @@ -37,7 +37,7 @@ namespace internal {
// EBCDIC. Technically we could use some smaller ranges, but that's even harder
// to read.

LIBC_INLINE static constexpr bool islower(int ch) {
LIBC_INLINE static constexpr bool islower(char ch) {
switch (ch) {
case 'a':
case 'b':
Expand Down Expand Up @@ -71,7 +71,7 @@ LIBC_INLINE static constexpr bool islower(int ch) {
}
}

LIBC_INLINE static constexpr bool isupper(int ch) {
LIBC_INLINE static constexpr bool isupper(char ch) {
switch (ch) {
case 'A':
case 'B':
Expand Down Expand Up @@ -105,7 +105,7 @@ LIBC_INLINE static constexpr bool isupper(int ch) {
}
}

LIBC_INLINE static constexpr bool isdigit(int ch) {
LIBC_INLINE static constexpr bool isdigit(char ch) {
switch (ch) {
case '0':
case '1':
Expand All @@ -123,7 +123,7 @@ LIBC_INLINE static constexpr bool isdigit(int ch) {
}
}

LIBC_INLINE static constexpr int tolower(int ch) {
LIBC_INLINE static constexpr char tolower(char ch) {
switch (ch) {
case 'A':
return 'a';
Expand Down Expand Up @@ -182,7 +182,7 @@ LIBC_INLINE static constexpr int tolower(int ch) {
}
}

LIBC_INLINE static constexpr int toupper(int ch) {
LIBC_INLINE static constexpr char toupper(char ch) {
switch (ch) {
case 'a':
return 'A';
Expand Down Expand Up @@ -241,7 +241,7 @@ LIBC_INLINE static constexpr int toupper(int ch) {
}
}

LIBC_INLINE static constexpr bool isalpha(int ch) {
LIBC_INLINE static constexpr bool isalpha(char ch) {
switch (ch) {
case 'a':
case 'b':
Expand Down Expand Up @@ -301,7 +301,7 @@ LIBC_INLINE static constexpr bool isalpha(int ch) {
}
}

LIBC_INLINE static constexpr bool isalnum(int ch) {
LIBC_INLINE static constexpr bool isalnum(char ch) {
switch (ch) {
case 'a':
case 'b':
Expand Down Expand Up @@ -371,7 +371,7 @@ LIBC_INLINE static constexpr bool isalnum(int ch) {
}
}

LIBC_INLINE static constexpr int b36_char_to_int(int ch) {
LIBC_INLINE static constexpr int b36_char_to_int(char ch) {
switch (ch) {
case '0':
return 0;
Expand Down Expand Up @@ -476,7 +476,7 @@ LIBC_INLINE static constexpr int b36_char_to_int(int ch) {
}
}

LIBC_INLINE static constexpr int int_to_b36_char(int num) {
LIBC_INLINE static constexpr char int_to_b36_char(int num) {
// Can't actually use LIBC_ASSERT here because it depends on integer_to_string
// which depends on this.

Expand Down Expand Up @@ -559,7 +559,7 @@ LIBC_INLINE static constexpr int int_to_b36_char(int num) {
}
}

LIBC_INLINE static constexpr bool isspace(int ch) {
LIBC_INLINE static constexpr bool isspace(char ch) {
switch (ch) {
case ' ':
case '\t':
Expand All @@ -574,7 +574,7 @@ LIBC_INLINE static constexpr bool isspace(int ch) {
}

// not yet encoding independent.
LIBC_INLINE static constexpr bool isgraph(int ch) {
LIBC_INLINE static constexpr bool isgraph(char ch) {
return 0x20 < ch && ch < 0x7f;
}

Expand Down
5 changes: 2 additions & 3 deletions libc/src/__support/integer_to_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,8 @@ template <typename T, typename Fmt = radix::Dec> class IntegerToString {
using UNSIGNED_T = make_integral_or_big_int_unsigned_t<T>;

LIBC_INLINE static char digit_char(uint8_t digit) {
const int result = internal::int_to_b36_char(digit);
return static_cast<char>(Fmt::IS_UPPERCASE ? internal::toupper(result)
: result);
const char result = internal::int_to_b36_char(digit);
return Fmt::IS_UPPERCASE ? internal::toupper(result) : result;
}

LIBC_INLINE static void
Expand Down
23 changes: 23 additions & 0 deletions libc/src/ctype/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_entrypoint_object(
isalnum.h
DEPENDS
libc.include.ctype
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -16,6 +17,7 @@ add_entrypoint_object(
HDRS
isalpha.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand Down Expand Up @@ -50,6 +52,7 @@ add_entrypoint_object(
HDRS
isdigit.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -60,6 +63,7 @@ add_entrypoint_object(
HDRS
isgraph.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -70,6 +74,7 @@ add_entrypoint_object(
HDRS
islower.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -88,6 +93,7 @@ add_entrypoint_object(
HDRS
ispunct.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -97,6 +103,9 @@ add_entrypoint_object(
isspace.cpp
HDRS
isspace.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

add_entrypoint_object(
Expand All @@ -106,6 +115,7 @@ add_entrypoint_object(
HDRS
isupper.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -116,6 +126,7 @@ add_entrypoint_object(
HDRS
isxdigit.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -126,6 +137,7 @@ add_entrypoint_object(
HDRS
tolower.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -144,6 +156,7 @@ add_entrypoint_object(
HDRS
toupper.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

Expand All @@ -160,6 +173,7 @@ add_entrypoint_object(
isalnum_l.h
DEPENDS
libc.include.ctype
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
Expand All @@ -171,6 +185,7 @@ add_entrypoint_object(
HDRS
isalpha_l.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
Expand Down Expand Up @@ -202,6 +217,7 @@ add_entrypoint_object(
HDRS
isdigit_l.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
Expand All @@ -224,6 +240,7 @@ add_entrypoint_object(
HDRS
islower_l.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
Expand Down Expand Up @@ -257,6 +274,8 @@ add_entrypoint_object(
isspace_l.h
DEPENDS
libc.hdr.types.locale_t
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
)

add_entrypoint_object(
Expand All @@ -266,6 +285,7 @@ add_entrypoint_object(
HDRS
isupper_l.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
Expand All @@ -277,6 +297,7 @@ add_entrypoint_object(
HDRS
isxdigit_l.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
Expand All @@ -288,6 +309,7 @@ add_entrypoint_object(
HDRS
tolower_l.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
Expand All @@ -299,6 +321,7 @@ add_entrypoint_object(
HDRS
toupper_l.h
DEPENDS
libc.src.__support.CPP.limits
libc.src.__support.ctype_utils
libc.hdr.types.locale_t
)
7 changes: 5 additions & 2 deletions libc/src/ctype/isalnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
//===----------------------------------------------------------------------===//

#include "src/ctype/isalnum.h"
#include "src/__support/ctype_utils.h"

#include "src/__support/CPP/limits.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, isalnum, (int c)) {
return static_cast<int>(internal::isalnum(static_cast<unsigned>(c)));
if (c < 0 || c > cpp::numeric_limits<unsigned char>::max())
return 0;
return static_cast<int>(internal::isalnum(static_cast<char>(c)));
}

} // namespace LIBC_NAMESPACE_DECL
7 changes: 5 additions & 2 deletions libc/src/ctype/isalnum_l.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
//===----------------------------------------------------------------------===//

#include "src/ctype/isalnum_l.h"
#include "src/__support/ctype_utils.h"

#include "src/__support/CPP/limits.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, isalnum_l, (int c, locale_t)) {
return static_cast<int>(internal::isalnum(static_cast<unsigned>(c)));
if (c < 0 || c > cpp::numeric_limits<unsigned char>::max())
return 0;
return static_cast<int>(internal::isalnum(static_cast<char>(c)));
}

} // namespace LIBC_NAMESPACE_DECL
5 changes: 4 additions & 1 deletion libc/src/ctype/isalpha.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

#include "src/ctype/isalpha.h"

#include "src/__support/CPP/limits.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, isalpha, (int c)) {
return static_cast<int>(internal::isalpha(static_cast<unsigned>(c)));
if (c < 0 || c > cpp::numeric_limits<unsigned char>::max())
return 0;
return static_cast<int>(internal::isalpha(static_cast<char>(c)));
}

} // namespace LIBC_NAMESPACE_DECL
5 changes: 4 additions & 1 deletion libc/src/ctype/isalpha_l.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@

#include "src/ctype/isalpha_l.h"

#include "src/__support/CPP/limits.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, isalpha_l, (int c, locale_t)) {
return static_cast<int>(internal::isalpha(static_cast<unsigned>(c)));
if (c < 0 || c > cpp::numeric_limits<unsigned char>::max())
return 0;
return static_cast<int>(internal::isalpha(static_cast<char>(c)));
}

} // namespace LIBC_NAMESPACE_DECL
6 changes: 5 additions & 1 deletion libc/src/ctype/isdigit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
//===----------------------------------------------------------------------===//

#include "src/ctype/isdigit.h"

#include "src/__support/CPP/limits.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"
#include "src/__support/macros/config.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, isdigit, (int c)) {
return static_cast<int>(internal::isdigit(static_cast<unsigned>(c)));
if (c < 0 || c > cpp::numeric_limits<unsigned char>::max())
return 0;
return static_cast<int>(internal::isdigit(static_cast<char>(c)));
}

} // namespace LIBC_NAMESPACE_DECL
Loading
Loading