mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-30 18:02:02 +00:00
Update fmt for runes; Add strings.contains_rune
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user