diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-24 16:58:39 +0100 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-01-24 16:58:39 +0100 |
| commit | 6a7d821fcc42e58bb90b78f484c70dfa42a56c91 (patch) | |
| tree | 1d5eede5f6831754489e9ed9677fa9d0006c40df /core | |
| parent | 01e29bf27ef0204f586b856363f7a3bf5138052d (diff) | |
| parent | 42ab882db4a6d5765c68021ade010b468ff4531e (diff) | |
Merge remote-tracking branch 'upstream/master' into parser-fix
Diffstat (limited to 'core')
| -rw-r--r-- | core/c/libc/stdio.odin | 2 | ||||
| -rw-r--r-- | core/runtime/core_builtin.odin | 4 | ||||
| -rw-r--r-- | core/strings/strings.odin | 70 |
3 files changed, 75 insertions, 1 deletions
diff --git a/core/c/libc/stdio.odin b/core/c/libc/stdio.odin index 4a39c22e9..c5c936d16 100644 --- a/core/c/libc/stdio.odin +++ b/core/c/libc/stdio.odin @@ -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 diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin index 44da894c1..3bafc0b1d 100644 --- a/core/runtime/core_builtin.odin +++ b/core/runtime/core_builtin.odin @@ -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 { diff --git a/core/strings/strings.odin b/core/strings/strings.odin index b93c5bcc0..67046c669 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -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 +} |