Merge remote-tracking branch 'upstream/master' into parser-fix

This commit is contained in:
Daniel Gavin
2022-01-24 16:58:39 +01:00
19 changed files with 130 additions and 1753 deletions
+1 -1
View File
@@ -149,7 +149,7 @@ foreign libc {
putchar :: proc() -> int ---
puts :: proc(s: cstring) -> int ---
ungetc :: proc(c: int, stream: ^FILE) -> int ---
fread :: proc(ptr: rawptr, size: size_t, stream: ^FILE) -> size_t ---
fread :: proc(ptr: rawptr, size: size_t, nmemb: size_t, stream: ^FILE) -> size_t ---
fwrite :: proc(ptr: rawptr, size: size_t, nmemb: size_t, stream: ^FILE) -> size_t ---
// 7.21.9 File positioning functions
+4
View File
@@ -614,6 +614,10 @@ raw_data :: proc{raw_array_data, raw_slice_data, raw_dynamic_array_data, raw_str
@(disabled=ODIN_DISABLE_ASSERT)
assert :: proc(condition: bool, message := "", loc := #caller_location) {
if !condition {
// NOTE(bill): This is wrapped in a procedure call
// to improve performance to make the CPU not
// execute speculatively, making it about an order of
// magnitude faster
proc(message: string, loc: Source_Code_Location) {
p := context.assertion_failure_proc
if p == nil {
+70
View File
@@ -353,6 +353,76 @@ split_after_n_iterator :: proc(s: ^string, sep: string, n: int) -> (string, bool
}
@(private)
_trim_cr :: proc(s: string) -> string {
n := len(s)
if n > 0 {
if s[n-1] == '\r' {
return s[:n-1]
}
}
return s
}
split_lines :: proc(s: string, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, 0, -1, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_n :: proc(s: string, n: int, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, 0, n, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_after :: proc(s: string, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, len(sep), -1, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_after_n :: proc(s: string, n: int, allocator := context.allocator) -> []string {
sep :: "\n"
lines := _split(s, sep, len(sep), n, allocator)
for line in &lines {
line = _trim_cr(line)
}
return lines
}
split_lines_iterator :: proc(s: ^string) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, 0, -1) or_return
return _trim_cr(line), true
}
split_lines_n_iterator :: proc(s: ^string, n: int) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, 0, n) or_return
return _trim_cr(line), true
}
split_lines_after_iterator :: proc(s: ^string) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, len(sep), -1) or_return
return _trim_cr(line), true
}
split_lines_after_n_iterator :: proc(s: ^string, n: int) -> (line: string, ok: bool) {
sep :: "\n"
line = _split_iterator(s, sep, len(sep), n) or_return
return _trim_cr(line), true
}