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] Fix String.split() and start fixing String.__len__() #2960

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5e0085b
start fixing isspace and str len
martinvuyk Jun 5, 2024
954d5ab
remove damn install_id
martinvuyk Jun 5, 2024
84cca7f
Merge remote-tracking branch 'upstream/nightly' into fix-string-split
martinvuyk Jun 11, 2024
7e8a33d
fix details
martinvuyk Jun 11, 2024
944d851
fix details
martinvuyk Jun 11, 2024
968a3e3
fix details
martinvuyk Jun 11, 2024
43d8b10
fix details
martinvuyk Jun 11, 2024
b1f3055
fix details
martinvuyk Jun 11, 2024
8e5c0ca
fix details
martinvuyk Jun 11, 2024
cbe54cd
fix details
martinvuyk Jun 11, 2024
6e7754f
fix details
martinvuyk Jun 12, 2024
64645ee
fix details
martinvuyk Jun 12, 2024
0d08744
Merge remote-tracking branch 'upstream/nightly' into fix-string-split
martinvuyk Jun 19, 2024
4c23e3a
Merge remote-tracking branch 'upstream/nightly' into fix-string-split
martinvuyk Jun 30, 2024
2fd95ce
fix suggestions
martinvuyk Jul 2, 2024
ccc3d7f
Merge remote-tracking branch 'upstream/nightly' into fix-string-split
martinvuyk Jul 2, 2024
2cb0880
add llvm intrinsics issue #933
martinvuyk Jul 2, 2024
051e6eb
fix detail
martinvuyk Jul 2, 2024
b32daf3
move isspace and stringiter impl to stringslice
martinvuyk Jul 8, 2024
036140b
Merge remote-tracking branch 'upstream/nightly' into fix-string-split
martinvuyk Jul 8, 2024
0569025
fix byte_length usage
martinvuyk Jul 8, 2024
1a91e5f
fix byte_length usage in tests
martinvuyk Jul 8, 2024
01e5450
remove deprecation warning
martinvuyk Jul 8, 2024
cbebc06
add deprecation warning, fix docstring
martinvuyk Jul 8, 2024
05d33ac
fix uses of String.__len__
martinvuyk Jul 8, 2024
b10fbc1
fix uses of String.__len__ and remove deprecation warning
martinvuyk Jul 8, 2024
d579222
add _byte_length with deprecation warning
martinvuyk Jul 8, 2024
e51df82
split isspace and iter into another PR
martinvuyk Jul 9, 2024
1c952c4
fix dangling import and isspace use
martinvuyk Jul 9, 2024
633ba24
fix isspace
martinvuyk Jul 9, 2024
b7630b6
add suggestions
martinvuyk Jul 9, 2024
10d88ec
add suggestions
martinvuyk Jul 9, 2024
c6343ab
Merge remote-tracking branch 'upstream/nightly' into fix-string-split
martinvuyk Jul 9, 2024
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
8 changes: 4 additions & 4 deletions stdlib/src/base64/base64.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn b64encode(str: String) -> String:
alias lookup = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
var b64chars = lookup.unsafe_ptr()

var length = len(str)
var length = str.byte_length()
var out = String._buffer_type(capacity=length + 1)

@parameter
Expand Down Expand Up @@ -121,7 +121,7 @@ fn b64decode(str: String) -> String:
Returns:
The decoded string.
"""
var n = len(str)
var n = str.byte_length()
debug_assert(n % 4 == 0, "Input length must be divisible by 4")

var p = String._buffer_type(capacity=n + 1)
Expand Down Expand Up @@ -170,7 +170,7 @@ fn b16encode(str: String) -> String:
alias lookup = "0123456789ABCDEF"
var b16chars = lookup.unsafe_ptr()

var length = len(str)
var length = str.byte_length()
var out = List[UInt8](capacity=length * 2 + 1)

@parameter
Expand Down Expand Up @@ -221,7 +221,7 @@ fn b16decode(str: String) -> String:

return -1

var n = len(str)
var n = str.byte_length()
debug_assert(n % 2 == 0, "Input length must be divisible by 2")

var p = List[UInt8](capacity=n // 2 + 1)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/builtin/error.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct Error(
Returns:
The constructed Error object.
"""
var length = len(src)
var length = src.byte_length()
var dest = UnsafePointer[UInt8].alloc(length + 1)
memcpy(
dest=dest,
Expand Down
8 changes: 4 additions & 4 deletions stdlib/src/builtin/file.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ struct FileHandle:
var bytes = file.read(ptr, 8)
print("bytes read", bytes)

var first_element = ptr.load(0)
var first_element = ptr[0]
print(first_element)

# Skip 2 elements
Expand Down Expand Up @@ -374,15 +374,15 @@ struct FileHandle:
```mojo
import os
var f = open("/tmp/example.txt", "r")
f.seek(os.SEEK_CUR, 32)
_ = f.seek(32, os.SEEK_CUR)
```

Start from 32 bytes from the end of the file:

```mojo
import os
var f = open("/tmp/example.txt", "r")
f.seek(os.SEEK_END, -32)
_ = f.seek(-32, os.SEEK_END)
```
.
"""
Expand All @@ -409,7 +409,7 @@ struct FileHandle:
Args:
data: The data to write to the file.
"""
self._write(data.unsafe_ptr(), len(data))
self._write(data.unsafe_ptr(), data.byte_length())

fn write(self, data: Span[UInt8, _]) raises:
"""Write a borrowed sequence of data to the file.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/src/builtin/io.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ fn _put(x: DType, file: FileDescriptor = stdout):
@no_inline
fn _put(x: StringSlice, file: FileDescriptor = stdout):
# Avoid printing "(null)" for an empty/default constructed `String`
var str_len = x._byte_length()
var str_len = x.byte_length()

if not str_len:
return
Expand All @@ -341,7 +341,7 @@ fn _put(x: StringSlice, file: FileDescriptor = stdout):

# The string can be printed, so that's fine.
if str_len < MAX_STR_LEN:
_printf["%.*s"](x._byte_length(), x.unsafe_ptr(), file=file)
_printf["%.*s"](x.byte_length(), x.unsafe_ptr(), file=file)
return

# The string is large, then we need to chunk it.
Expand Down
Loading