aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-11-26 23:54:23 +0000
committergingerBill <bill@gingerbill.org>2017-11-26 23:54:23 +0000
commit3e1ff0ec67806f73c09f02dfbb3ce7f252ea6738 (patch)
treeb38d5ac3a86e81e2640b270e14e2301ad339c3f9 /core
parent65945dac099aff7d8d86468f4100a363b9b4ad1b (diff)
Update fmt for runes; Add `strings.contains_rune`
Diffstat (limited to 'core')
-rw-r--r--core/fmt.odin2
-rw-r--r--core/strings.odin19
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;
+}