From: Brendan Hansen Date: Sun, 6 Dec 2020 04:29:40 +0000 (-0600) Subject: string library bugfixes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=52526e3fd0c36e4334200515ee2f44ba9910c15a;p=onyx.git string library bugfixes --- diff --git a/core/string.onyx b/core/string.onyx index f6ede261..7a7b742f 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -97,6 +97,15 @@ string_equal :: proc (str1: string, str2: string) -> bool { return true; } +string_starts_with :: proc (str1: string, str2: string) -> bool { + if str1.count < str2.count do return false; + while i := 0; i < str2.count { + if str1[i] != str2[i] do return false; + i += 1; + } + return true; +} + string_strip_leading_whitespace :: proc (str: ^string) { while true do switch str.data[0] { case #char " ", #char "\t", #char "\n", #char "\r" { @@ -337,11 +346,13 @@ string_read_line :: proc (str: ^string, out: ^string) { } string_advance_line :: proc (str: ^string) { + if str.count == 0 do return; + adv := 0; while str.data[adv] != #char "\n" do adv += 1; - str.data += adv; - str.count -= adv; + str.data += adv + 1; + str.count -= adv + 1; } string_read :: proc {