Skip to content

Commit 88ba06d

Browse files
authored
[libc] Addressed todo to make first_non_whitespace to return an idx instead of ptr (#148004)
Addressed todo to make first_non_whitespace to return an idx instead of ptr
1 parent 838701a commit 88ba06d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

libc/src/__support/str_to_float.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ LIBC_INLINE StrToNumResult<T> strtofloatingpoint(const char *__restrict src) {
11351135

11361136
int error = 0;
11371137

1138-
size_t index = static_cast<size_t>(first_non_whitespace(src) - src);
1138+
size_t index = first_non_whitespace(src);
11391139

11401140
if (src[index] == '+' || src[index] == '-') {
11411141
sign = src[index];

libc/src/__support/str_to_integer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@
2929
namespace LIBC_NAMESPACE_DECL {
3030
namespace internal {
3131

32-
// Returns a pointer to the first character in src that is not a whitespace
32+
// Returns the idx to the first character in src that is not a whitespace
3333
// character (as determined by isspace())
34-
// TODO: Change from returning a pointer to returning a length.
35-
LIBC_INLINE const char *
34+
LIBC_INLINE size_t
3635
first_non_whitespace(const char *__restrict src,
3736
size_t src_len = cpp::numeric_limits<size_t>::max()) {
3837
size_t src_cur = 0;
3938
while (src_cur < src_len && internal::isspace(src[src_cur])) {
4039
++src_cur;
4140
}
42-
return src + src_cur;
41+
return src_cur;
4342
}
4443

4544
// checks if the next 3 characters of the string pointer are the start of a
@@ -96,7 +95,7 @@ strtointeger(const char *__restrict src, int base,
9695
if (base < 0 || base == 1 || base > 36)
9796
return {0, 0, EINVAL};
9897

99-
src_cur = static_cast<size_t>(first_non_whitespace(src, src_len) - src);
98+
src_cur = first_non_whitespace(src, src_len);
10099

101100
char result_sign = '+';
102101
if (src[src_cur] == '+' || src[src_cur] == '-') {

0 commit comments

Comments
 (0)