Strings galore!

This commit is contained in:
gingerBill
2016-08-05 21:07:25 +01:00
parent 4a303b5c3e
commit ba238c569a
12 changed files with 473 additions and 312 deletions
+7 -7
View File
@@ -1,23 +1,23 @@
putchar :: proc(c : i32) -> i32 #foreign
putchar :: proc(c: i32) -> i32 #foreign
print_string :: proc(s : string) {
print_string :: proc(s: string) {
for i := 0; i < len(s); i++ {
c := cast(i32)s[i];
putchar(c);
}
}
string_byte_reverse :: proc(s : string) {
string_byte_reverse :: proc(s: string) {
n := len(s);
for i := 0; i < n/2; i++ {
s[i], s[n-1-i] = s[n-1-i], s[i];
}
}
print_int :: proc(i : int, base : int) {
NUM_TO_CHAR_TABLE := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$";
print_int :: proc(i, base: int) {
NUM_TO_CHAR_TABLE :: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@$";
buf : [21]byte;
buf: [21]u8;
len := 0;
negative := false;
if i < 0 {
@@ -26,7 +26,7 @@ print_int :: proc(i : int, base : int) {
}
if i > 0 {
for i > 0 {
c : byte = NUM_TO_CHAR_TABLE[i % base];
c : u8 = NUM_TO_CHAR_TABLE[i % base];
buf[len] = c;
len++;
i /= base;