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 8 commits into
base: nightly
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ what we publish.

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

### 🛠️ Fixed

Expand Down
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
9 changes: 9 additions & 0 deletions stdlib/test/utils/test_stringref.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ from testing import assert_equal, assert_false, assert_raises, assert_true
from utils import StringRef


def test_stringref_from_pointer():
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_strref_from_start():
var str = StringRef("Hello")

Expand Down Expand Up @@ -169,6 +177,7 @@ def test_str_and_ref():


def main():
test_stringref_from_pointer()
test_strref_from_start()
test_stringref_split()
test_comparison_operators()
Expand Down
Loading