From 3e1ff0ec67806f73c09f02dfbb3ce7f252ea6738 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 26 Nov 2017 23:54:23 +0000 Subject: [PATCH] Update fmt for runes; Add `strings.contains_rune` --- core/fmt.odin | 2 +- core/strings.odin | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/fmt.odin b/core/fmt.odin index b68dacf12..39ddfa851 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -503,7 +503,7 @@ fmt_rune :: proc(fi: ^Fmt_Info, r: rune, verb: rune) { case 'c', 'r', 'v': write_rune(fi.buf, r); case: - fmt_bad_verb(fi, verb); + fmt_int(fi, u128(r), false, 32, verb); } } diff --git a/core/strings.odin b/core/strings.odin index f8697e46e..bc76e78d0 100644 --- a/core/strings.odin +++ b/core/strings.odin @@ -1,22 +1,29 @@ import "core:mem.odin" new_string :: proc(s: string) -> string { - c := make([]u8, len(s)+1); - copy(c, cast([]u8)s); + c := make([]byte, len(s)+1); + copy(c, cast([]byte)s); c[len(s)] = 0; return string(c[..len(s)]); } -new_c_string :: proc(s: string) -> ^u8 { - c := make([]u8, len(s)+1); - copy(c, cast([]u8)s); +new_c_string :: proc(s: string) -> ^byte { + c := make([]byte, len(s)+1); + copy(c, cast([]byte)s); c[len(s)] = 0; return &c[0]; } -to_odin_string :: proc(str: ^u8) -> string { +to_odin_string :: proc(str: ^byte) -> string { if str == nil do return ""; end := str; for end^ != 0 do end+=1; return string(mem.slice_ptr(str, end-str)); } + +contains_rune :: proc(s: string, r: rune) -> int { + for c, offset in s { + if c == r do return offset; + } + return -1; +}