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

Closed
Closed
Prev Previous commit
Merge remote-tracking branch 'upstream/main' into remove-string-strin…
…gref-dependencies
  • Loading branch information
martinvuyk committed Feb 1, 2025
commit d977fe57364b278c922f5415b6e0c4816b69a6ec
22 changes: 7 additions & 15 deletions stdlib/src/collections/string/string.mojo
Original file line number Diff line number Diff line change
@@ -436,18 +436,8 @@ fn atof(str_slice: StringSlice) raises -> Float64:
An floating point value that represents the string, or otherwise raises.
"""


fn _atof_error(str_ref: StringSlice) -> Error:
return Error("String is not convertible to float: '" + str(str_ref) + "'")


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

Please see its docstring for details.
"""
if not str_ref:
raise _atof_error(str_ref)
if not str_slice:
raise _atof_error(str_slice)

var result: Float64 = 0.0
var exponent: Int = 0
@@ -474,7 +464,7 @@ fn _atof(str_ref: StringSlice) raises -> Float64:
elif buff[start] == ord_minus:
start += 1
sign = -1
alias S = StringSlice[__type_of(str_ref).origin]
alias S = StringSlice[buff.origin]
if (str_len - start) >= 3:
if S(ptr=buff + start, length=3) == "nan":
return FloatLiteral.nan
@@ -900,8 +890,10 @@ struct String(
start, end, step = span.indices(self.byte_length())
var r = range(start, end, step)
if step == 1:
return StringSlice[__origin_of(self)](
ptr=self._buffer.data + start, length=len(r)
return String(
StringSlice[__origin_of(self._buffer)](
ptr=self._buffer.data + start, length=len(r)
)
)

var buffer = Self._buffer_type()
You are viewing a condensed version of this merge commit. You can view the full changes here.