mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Use for x in y construct for bytes iteration
This cannot be applied to the `strings` version, as that would cause a rune-by-rune iteration, not a byte-by-byte one.
This commit is contained in:
@@ -298,8 +298,8 @@ split_after_iterator :: proc(s: ^[]byte, sep: []byte) -> ([]byte, bool) {
|
|||||||
|
|
||||||
index_byte :: proc(s: []byte, c: byte) -> int {
|
index_byte :: proc(s: []byte, c: byte) -> int {
|
||||||
_index_byte :: #force_inline proc "contextless" (s: []byte, c: byte) -> int {
|
_index_byte :: #force_inline proc "contextless" (s: []byte, c: byte) -> int {
|
||||||
for i := 0; i < len(s); i += 1 {
|
for ch, i in s {
|
||||||
if s[i] == c {
|
if ch == c {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,8 +319,8 @@ index_byte :: proc(s: []byte, c: byte) -> int {
|
|||||||
// Returns -1 if c is not present
|
// Returns -1 if c is not present
|
||||||
last_index_byte :: proc(s: []byte, c: byte) -> int {
|
last_index_byte :: proc(s: []byte, c: byte) -> int {
|
||||||
_last_index_byte :: #force_inline proc "contextless" (s: []byte, c: byte) -> int {
|
_last_index_byte :: #force_inline proc "contextless" (s: []byte, c: byte) -> int {
|
||||||
for i := len(s)-1; i >= 0; i -= 1 {
|
#reverse for ch, i in s {
|
||||||
if s[i] == c {
|
if ch == c {
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user