Skip to content

Commit

Permalink
Implement NumPyOS_ascii_islower/isupper and use those
Browse files Browse the repository at this point in the history
  • Loading branch information
lysnikolaou committed Feb 16, 2024
1 parent a9711bb commit 96646fb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions numpy/_core/src/common/numpyos.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,28 @@ NumPyOS_ascii_isalnum(char c)
return NumPyOS_ascii_isdigit(c) || NumPyOS_ascii_isalpha(c);
}

/*
* NumPyOS_ascii_islower:
*
* Same as islower under C locale
*/
NPY_NO_EXPORT int
NumPyOS_ascii_islower(char c)
{
return c >= 'a' && c <= 'z';
}

/*
* NumPyOS_ascii_isupper:
*
* Same as isupper under C locale
*/
NPY_NO_EXPORT int
NumPyOS_ascii_isupper(char c)
{
return (c >= 'A' && c <= 'Z')
}


/*
* NumPyOS_ascii_tolower:
Expand Down
6 changes: 6 additions & 0 deletions numpy/_core/src/common/numpyos.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ NumPyOS_ascii_isdigit(char c);
NPY_NO_EXPORT int
NumPyOS_ascii_isalnum(char c);

NPY_NO_EXPORT int
NumPyOS_ascii_islower(char c);

NPY_NO_EXPORT int
NumPyOS_ascii_isupper(char c);

/* Convert a string to an int in an arbitrary base */
NPY_NO_EXPORT npy_longlong
NumPyOS_strtoll(const char *str, char **endptr, int base);
Expand Down
4 changes: 2 additions & 2 deletions numpy/_core/src/umath/string_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ template<>
inline bool
codepoint_islower<ENCODING::ASCII>(npy_ucs4 code)
{
return Py_ISLOWER((char) code);
return NumPyOS_ascii_islower(code);
}

template<>
Expand All @@ -199,7 +199,7 @@ template<>
inline bool
codepoint_isupper<ENCODING::ASCII>(npy_ucs4 code)
{
return Py_ISUPPER((char) code);
return NumPyOS_ascii_isupper(code);
}

template<>
Expand Down

0 comments on commit 96646fb

Please sign in to comment.