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 StringRef.strip() #3868

Open
wants to merge 12 commits into
base: nightly
Choose a base branch
from
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ what we publish.

### ❌ Removed

- `StringRef` is being deprecated. Use `StringSlice` instead.
- removed `StringRef.strip()`

### 🛠️ Fixed
18 changes: 0 additions & 18 deletions stdlib/src/utils/stringref.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -597,24 +597,6 @@ struct StringRef(

return StringRef(data, length)

fn strip(self) -> StringRef:
"""Gets a StringRef with leading and trailing whitespaces removed.
This only takes C spaces into account: " \\t\\n\\v\\f\\r".

For example, `" mojo "` returns `"mojo"`.

Returns:
A StringRef with leading and trailing whitespaces removed.
"""
var start: Int = 0
var end: Int = len(self)
var ptr = self.unsafe_ptr()
while start < end and _isspace(ptr[start]):
start += 1
while end > start and _isspace(ptr[end - 1]):
end -= 1
return StringRef(ptr + start, end - start)

fn split(self, delimiter: StringRef) raises -> List[StringRef]:
"""Split the StringRef by a delimiter.

Expand Down
58 changes: 0 additions & 58 deletions stdlib/test/collections/test_string.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -235,60 +235,6 @@ def test_string_join():
assert_equal(s6, "1,2,3")


def test_string_literal_join():
martinvuyk marked this conversation as resolved.
Show resolved Hide resolved
var s2 = ",".join(List[UInt8](1, 2, 3))
assert_equal(s2, "1,2,3")

var s3 = ",".join(List[UInt8](1, 2, 3, 4, 5, 6, 7, 8, 9))
assert_equal(s3, "1,2,3,4,5,6,7,8,9")

var s4 = ",".join(List[UInt8]())
assert_equal(s4, "")

var s5 = ",".join(List[UInt8](1))
assert_equal(s5, "1")


def test_stringref():
var a = StringRef("AAA")
var b = StringRef("BBB")
var c = StringRef("AAA")

assert_equal(3, len(a))
assert_equal(3, len(b))
assert_equal(3, len(c))
assert_equal(4, len("ABBA"))

# Equality operators
assert_not_equal(a, b)
assert_not_equal(b, a)

# Self equality
assert_equal(a, a)

# Value equality
assert_equal(a, c)


def test_stringref_from_dtypepointer():
martinvuyk marked this conversation as resolved.
Show resolved Hide resolved
var a = StringRef("AAA")
var b = StringRef(ptr=a.data)
assert_equal(3, len(a))
assert_equal(3, len(b))
assert_equal(a, b)


def test_stringref_strip():
var a = StringRef(" mojo rocks ")
var b = StringRef("mojo ")
var c = StringRef(" mojo")
var d = StringRef("")
assert_equal(a.strip(), "mojo rocks")
assert_equal(b.strip(), "mojo")
assert_equal(c.strip(), "mojo")
assert_equal(d.strip(), "")


def test_ord():
# Regular ASCII
assert_equal(ord("A"), 65)
Expand Down Expand Up @@ -1603,10 +1549,6 @@ def main():
test_stringable()
test_repr()
test_string_join()
test_string_literal_join()
test_stringref()
test_stringref_from_dtypepointer()
test_stringref_strip()
test_ord()
test_chr()
test_string_indexing()
Expand Down
Loading