Pārlūkot izejas kodu

Add `utf8.rune_index`

gingerBill 6 gadi atpakaļ
vecāks
revīzija
1da0668653
1 mainītis faili ar 13 papildinājumiem un 2 dzēšanām
  1. 13 2
      core/unicode/utf8/utf8.odin

+ 13 - 2
core/unicode/utf8/utf8.odin

@@ -167,9 +167,20 @@ decode_last_rune :: proc(s: []u8) -> (rune, int) {
 	return r, size;
 }
 
+rune_index :: proc(s: string, index: int) -> (r: rune = RUNE_ERROR, ok: bool = false) {
+	if index < 0 {
+		return;
+	}
 
-
-
+	i := 0;
+	for c in s {
+		if i == index {
+			return r, true;
+		}
+		i += 1;
+	}
+	return;
+}
 
 valid_rune :: proc(r: rune) -> bool {
 	if r < 0 {