瀏覽代碼

Merge pull request #1640 from Lperlind/split-iterator-byte

Add split_iterator_byte
gingerBill 3 年之前
父節點
當前提交
84cee5d9d5
共有 1 個文件被更改,包括 19 次插入0 次删除
  1. 19 0
      core/strings/strings.odin

+ 19 - 0
core/strings/strings.odin

@@ -339,6 +339,25 @@ _split_iterator :: proc(s: ^string, sep: string, sep_save: int) -> (res: string,
 	return
 	return
 }
 }
 
 
+@private
+_split_by_byte_iterator :: proc(s: ^string, sep: u8) -> (res: string, ok: bool) {
+	m := index_byte(s^, sep)
+	if m < 0 {
+		// not found
+		res = s[:]
+		ok = res != ""
+		s^ = {}
+	} else {
+		res = s[:m]
+		ok = true
+		s^ = s[m+1:]
+	}
+	return
+}
+
+split_by_byte_iterator :: proc(s: ^string, sep: u8) -> (string, bool) {
+	return _split_by_byte_iterator(s, sep)
+}
 
 
 split_iterator :: proc(s: ^string, sep: string) -> (string, bool) {
 split_iterator :: proc(s: ^string, sep: string) -> (string, bool) {
 	return _split_iterator(s, sep, 0)
 	return _split_iterator(s, sep, 0)