Skip to content

Commit 9679d3f

Browse files
author
Sriya Pratipati
committed
added nullptr handling and made functions static
1 parent f2a5e8a commit 9679d3f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

libc/src/wchar/wchar_utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
1818
namespace internal {
1919

2020
// returns true if the character exists in the string
21-
LIBC_INLINE bool internal_wcschr(wchar_t c, const wchar_t *str) {
21+
LIBC_INLINE static bool wcschr(wchar_t c, const wchar_t *str) {
2222
for (int n = 0; str[n]; ++n) {
2323
if (str[n] == c)
2424
return true;
@@ -28,11 +28,11 @@ LIBC_INLINE bool internal_wcschr(wchar_t c, const wchar_t *str) {
2828

2929
// bool should be true for wcscspn for complimentary span
3030
// should be false for wcsspn since we want it to span
31-
LIBC_INLINE size_t inline_wcsspn(const wchar_t *s1, const wchar_t *s2,
31+
LIBC_INLINE static size_t wcsspn(const wchar_t *s1, const wchar_t *s2,
3232
bool not_match_set) {
3333
size_t i = 0;
3434
for (; s1[i]; ++i) {
35-
bool in_set = internal_wcschr(s1[i], s2);
35+
bool in_set = wcschr(s1[i], s2);
3636
if (in_set == not_match_set)
3737
return i;
3838
}

libc/src/wchar/wcscspn.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#include "hdr/types/wchar_t.h"
1313
#include "src/__support/common.h"
1414
#include "src/__support/macros/config.h"
15+
#include "src/__support/macros/null_check.h"
1516
#include "wchar_utils.h"
1617

1718
namespace LIBC_NAMESPACE_DECL {
1819

1920
LLVM_LIBC_FUNCTION(size_t, wcscspn, (const wchar_t *s1, const wchar_t *s2)) {
20-
return internal::inline_wcsspn(s1, s2, true);
21+
LIBC_CRASH_ON_NULLPTR(s1);
22+
LIBC_CRASH_ON_NULLPTR(s2);
23+
return internal::wcsspn(s1, s2, /*not_match_set=*/true);
2124
}
2225

2326
} // namespace LIBC_NAMESPACE_DECL

libc/src/wchar/wcsspn.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
#include "hdr/types/wchar_t.h"
1313
#include "src/__support/common.h"
1414
#include "src/__support/macros/config.h"
15+
#include "src/__support/macros/null_check.h"
1516
#include "wchar_utils.h"
1617

1718
namespace LIBC_NAMESPACE_DECL {
1819

1920
LLVM_LIBC_FUNCTION(size_t, wcsspn, (const wchar_t *s1, const wchar_t *s2)) {
20-
return internal::inline_wcsspn(s1, s2, false);
21+
LIBC_CRASH_ON_NULLPTR(s1);
22+
LIBC_CRASH_ON_NULLPTR(s2);
23+
return internal::wcsspn(s1, s2, /*not_match_set=*/false);
2124
}
2225

2326
} // namespace LIBC_NAMESPACE_DECL

0 commit comments

Comments
 (0)