aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/bytes.md4
-rw-r--r--docs/text.md6
-rw-r--r--environment.c2
-rw-r--r--examples/base64/base64.tm6
-rw-r--r--test/text.tm6
5 files changed, 12 insertions, 12 deletions
diff --git a/docs/bytes.md b/docs/bytes.md
index 0b618339..9453fac3 100644
--- a/docs/bytes.md
+++ b/docs/bytes.md
@@ -4,8 +4,8 @@ Byte values have the type `Byte`, which corresponds to an unsigned 8-bit
integer ranging from 0 to 255. It is generally recommended to use `Int8`
instead of `Byte` when performing math operations, however, `Byte`s are used in
API methods for `Text` and `Path` that deal with raw binary data, such as
-`Path.read_bytes()` and `Text.utf8_bytes()`. Byte literals can be written as an
-integer with a `[B]` suffix, e.g. `255[B]`.
+`Path.read_bytes()` and `Text.bytes()`. Byte literals can be written using
+the `Byte()` constructor: `Byte(5)`.
# Byte Methods
diff --git a/docs/text.md b/docs/text.md
index d0179bc4..7557f05c 100644
--- a/docs/text.md
+++ b/docs/text.md
@@ -455,7 +455,7 @@ indices are counted from the back of the text, so `-1` means the last cluster,
---
-## `utf8_bytes`
+## `bytes`
**Description:**
Converts a `Text` value to an array of bytes representing a UTF8 encoding of
@@ -463,7 +463,7 @@ the text.
**Signature:**
```tomo
-func utf8_bytes(text: Text -> [Byte])
+func bytes(text: Text -> [Byte])
```
**Parameters:**
@@ -475,7 +475,7 @@ An array of bytes (`[Byte]`) representing the text in UTF8 encoding.
**Example:**
```tomo
->> "Amélie":utf8_bytes()
+>> "Amélie":bytes()
= [65[B], 109[B], 195[B], 169[B], 108[B], 105[B], 101[B]] : [Byte]
```
diff --git a/environment.c b/environment.c
index 3ded0af3..c98d55e4 100644
--- a/environment.c
+++ b/environment.c
@@ -386,6 +386,7 @@ env_t *new_compilation_unit(CORD libname)
{"Text", TEXT_TYPE, "Text_t", "Text$info", TypedArray(ns_entry_t,
{"as_c_string", "Text$as_c_string", "func(text:Text -> CString)"},
{"at", "Text$cluster", "func(text:Text, index:Int -> Text)"},
+ {"bytes", "Text$utf8_bytes", "func(text:Text -> [Byte])"},
{"codepoint_names", "Text$codepoint_names", "func(text:Text -> [Text])"},
{"ends_with", "Text$ends_with", "func(text,suffix:Text -> Bool)"},
{"each", "Text$each", "func(text:Text, pattern:Pattern, fn:func(match:Match))"},
@@ -413,7 +414,6 @@ env_t *new_compilation_unit(CORD libname)
{"trim", "Text$trim", "func(text:Text, pattern=$/{whitespace}/, trim_left=yes, trim_right=yes -> Text)"},
{"upper", "Text$upper", "func(text:Text -> Text)"},
{"utf32_codepoints", "Text$utf32_codepoints", "func(text:Text -> [Int32])"},
- {"utf8_bytes", "Text$utf8_bytes", "func(text:Text -> [Byte])"},
)},
{"Thread", THREAD_TYPE, "Thread_t", "Thread", TypedArray(ns_entry_t,
{"new", "Thread$new", "func(fn:func() -> Thread)"},
diff --git a/examples/base64/base64.tm b/examples/base64/base64.tm
index 2568a1d1..f3762628 100644
--- a/examples/base64/base64.tm
+++ b/examples/base64/base64.tm
@@ -1,6 +1,6 @@
# Base 64 encoding and decoding
-_enc := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/":utf8_bytes()
+_enc := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/":bytes()
_EQUAL_BYTE := Byte(0x3D)
@@ -26,7 +26,7 @@ _dec := [
lang Base64:
func parse(text:Text -> Base64?):
- return Base64.from_bytes(text:utf8_bytes())
+ return Base64.from_bytes(text:bytes())
func from_bytes(bytes:[Byte] -> Base64?):
output := [Byte(0) for _ in bytes.length * 4 / 3 + 4]
@@ -65,7 +65,7 @@ lang Base64:
return Text.from_bytes(b64:decode_bytes() or return !Text)
func decode_bytes(b64:Base64 -> [Byte]?):
- bytes := b64.text_content:utf8_bytes()
+ bytes := b64.text_content:bytes()
output := [Byte(0) for _ in bytes.length/4 * 3]
src := Int64(1)
dest := Int64(1)
diff --git a/test/text.tm b/test/text.tm
index cf95878e..173432ec 100644
--- a/test/text.tm
+++ b/test/text.tm
@@ -30,7 +30,7 @@ func main():
= ["A", "m", "é", "l", "i", "e"] : [Text]
>> amelie:utf32_codepoints()
= [Int32(65), Int32(109), Int32(233), Int32(108), Int32(105), Int32(101)]
- >> amelie:utf8_bytes()
+ >> amelie:bytes()
= [Byte(0x41), Byte(0x6D), Byte(0xC3), Byte(0xA9), Byte(0x6C), Byte(0x69), Byte(0x65)]
>> Text.from_bytes([:Byte 0x41, 0x6D, 0xC3, 0xA9, 0x6C, 0x69, 0x65])!
= "Amélie"
@@ -42,7 +42,7 @@ func main():
= ["A", "m", "é", "l", "i", "e"] : [Text]
>> amelie2:utf32_codepoints()
= [Int32(65), Int32(109), Int32(233), Int32(108), Int32(105), Int32(101)]
- >> amelie2:utf8_bytes()
+ >> amelie2:bytes()
= [Byte(0x41), Byte(0x6D), Byte(0xC3), Byte(0xA9), Byte(0x6C), Byte(0x69), Byte(0x65)]
>> amelie:codepoint_names()
@@ -126,7 +126,7 @@ func main():
= yes
>> c == Text.from_codepoints(c:utf32_codepoints())
= yes
- >> c == Text.from_bytes(c:utf8_bytes())!
+ >> c == Text.from_bytes(c:bytes())!
= yes
>> "one$(\n)two$(\n)three":lines()