mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-19 16:11:30 +00:00
Merge remote-tracking branch 'upstream/master' into parser-fix
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user