diff --git a/docs/changelog.md b/docs/changelog.md index 74c5137d6e..bc035807a2 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -118,6 +118,7 @@ what we publish. - `StringRef` is being deprecated. Use `StringSlice` instead. - Changed `sys.argv()` to return list of `StringSlice`. - removed `StringRef.startswith()` and `StringRef.endswith()` + - removed `StringRef.strip()` ### 🛠️ Fixed diff --git a/stdlib/src/utils/stringref.mojo b/stdlib/src/utils/stringref.mojo index 0b6877c9a1..e7b5f991c2 100644 --- a/stdlib/src/utils/stringref.mojo +++ b/stdlib/src/utils/stringref.mojo @@ -596,24 +596,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. diff --git a/stdlib/test/collections/string/test_string.mojo b/stdlib/test/collections/string/test_string.mojo index 74ae492479..0916f58b22 100644 --- a/stdlib/test/collections/string/test_string.mojo +++ b/stdlib/test/collections/string/test_string.mojo @@ -235,60 +235,6 @@ def test_string_join(): assert_equal(s6, "1,2,3") -def test_string_literal_join(): - 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(): - 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) @@ -1589,10 +1535,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() diff --git a/stdlib/test/utils/test_stringref.mojo b/stdlib/test/utils/test_stringref.mojo index 67965d22a4..8aa7e081be 100644 --- a/stdlib/test/utils/test_stringref.mojo +++ b/stdlib/test/utils/test_stringref.mojo @@ -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") @@ -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()