Skip to content
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

[stdlib] Remove String StringRef dependencies #3870

Open
wants to merge 5 commits into
base: nightly
Choose a base branch
from
Open
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
11 changes: 7 additions & 4 deletions stdlib/src/collections/string/string.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ fn _atof_error(str_ref: StringSlice) -> Error:


fn _atof(str_ref: StringSlice) raises -> Float64:
"""Implementation of `atof` for StringRef inputs.
"""Implementation of `atof` for StringSlice inputs.

Please see its docstring for details.
"""
Expand Down Expand Up @@ -502,10 +502,11 @@ fn _atof(str_ref: StringSlice) raises -> Float64:
elif buff[start] == ord_minus:
start += 1
sign = -1
alias S = StringSlice[__type_of(str_ref).origin]
if (str_len - start) >= 3:
if StringRef(buff + start, 3) == "nan":
if S(ptr=buff + start, length=3) == "nan":
return FloatLiteral.nan
if StringRef(buff + start, 3) == "inf":
elif S(ptr=buff + start, length=3) == "inf":
return FloatLiteral.infinity * sign
# read before dot
for pos in range(start, str_len):
Expand Down Expand Up @@ -1101,7 +1102,9 @@ struct String(
start, end, step = span.indices(self.byte_length())
var r = range(start, end, step)
if step == 1:
return StringRef(self._buffer.data + start, len(r))
return StringSlice[__origin_of(self)](
ptr=self._buffer.data + start, length=len(r)
)

var buffer = Self._buffer_type()
var result_len = len(r)
Expand Down
Loading