Update fmt for runes; Add strings.contains_rune

This commit is contained in:
gingerBill
2017-11-26 23:54:23 +00:00
parent 65945dac09
commit 3e1ff0ec67
2 changed files with 14 additions and 7 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}