aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2026-02-16 20:50:45 +0100
committerGitHub <noreply@github.com>2026-02-16 20:50:45 +0100
commitbfe1f234ec763fc79359f7614ae4cccab88780e7 (patch)
tree88d3f030745069e4f26b513a92aec6ec57387fd6
parent3adc5291131459ac1de03c2000c9adb7eb67fda6 (diff)
parent06b10f9ae800f478c643fb8fc8b6443f54b01224 (diff)
Merge pull request #6289 from wrathdoesthat/masterHEADmaster
Propagate allocator errors from certain unicode functions
-rw-r--r--core/unicode/utf16/utf16.odin5
-rw-r--r--core/unicode/utf8/utf8.odin13
2 files changed, 11 insertions, 7 deletions
diff --git a/core/unicode/utf16/utf16.odin b/core/unicode/utf16/utf16.odin
index 5cc996f8b..edd48e0f3 100644
--- a/core/unicode/utf16/utf16.odin
+++ b/core/unicode/utf16/utf16.odin
@@ -1,6 +1,7 @@
// Procedures and constants to support text-encoding in the `UTF-16` character encoding.
package utf16
+@(require) import "base:runtime"
import "core:unicode/utf8"
REPLACEMENT_CHAR :: '\ufffd'
@@ -127,10 +128,10 @@ decode_rune_in_string :: proc "contextless" (s: string16) -> (r: rune, width: in
return
}
-string_to_runes :: proc "odin" (s: string16, allocator := context.allocator) -> (runes: []rune) {
+string_to_runes :: proc "odin" (s: string16, allocator := context.allocator) -> (runes: []rune, err: runtime.Allocator_Error) #optional_allocator_error {
n := rune_count(s)
- runes = make([]rune, n, allocator)
+ runes = make([]rune, n, allocator) or_return
i := 0
for r in s {
runes[i] = r
diff --git a/core/unicode/utf8/utf8.odin b/core/unicode/utf8/utf8.odin
index 0b48a0cd8..85687b749 100644
--- a/core/unicode/utf8/utf8.odin
+++ b/core/unicode/utf8/utf8.odin
@@ -1,6 +1,8 @@
// Procedures and constants to support text-encoding in the `UTF-8` character encoding.
package utf8
+@(require) import "base:runtime"
+
RUNE_ERROR :: '\ufffd'
RUNE_SELF :: 0x80
RUNE_BOM :: 0xfeff
@@ -145,10 +147,10 @@ decode_rune_in_bytes :: proc "contextless" (s: []u8) -> (rune, int) {
}
@(require_results)
-string_to_runes :: proc "odin" (s: string, allocator := context.allocator) -> (runes: []rune) {
+string_to_runes :: proc "odin" (s: string, allocator := context.allocator) -> (runes: []rune, err: runtime.Allocator_Error) #optional_allocator_error {
n := rune_count_in_string(s)
- runes = make([]rune, n, allocator)
+ runes = make([]rune, n, allocator) or_return
i := 0
for r in s {
runes[i] = r
@@ -158,14 +160,14 @@ string_to_runes :: proc "odin" (s: string, allocator := context.allocator) -> (r
}
@(require_results)
-runes_to_string :: proc "odin" (runes: []rune, allocator := context.allocator) -> string {
+runes_to_string :: proc "odin" (runes: []rune, allocator := context.allocator) -> (s: string, err: runtime.Allocator_Error) #optional_allocator_error {
byte_count := 0
for r in runes {
_, w := encode_rune(r)
byte_count += w
}
- bytes := make([]byte, byte_count, allocator)
+ bytes := make([]byte, byte_count, allocator) or_return
offset := 0
for r in runes {
b, w := encode_rune(r)
@@ -173,7 +175,8 @@ runes_to_string :: proc "odin" (runes: []rune, allocator := context.allocator) -
offset += w
}
- return string(bytes)
+ s = string(bytes)
+ return
}