diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 23:33:22 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-08-31 23:33:22 -0400 |
| commit | 5fc7577b5a3bc2c445522dfd5b287e1c6eddc3e9 (patch) | |
| tree | 34d44c9330dc3ec71fc850b95b3412a1ce292cb8 /lib | |
| parent | a571ccffd795a595e990a3405dcf977aafc33c6c (diff) | |
Switch to using optional return values for list indexing.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/base64/CHANGES.md | 4 | ||||
| -rw-r--r-- | lib/base64/base64.tm | 34 | ||||
| -rw-r--r-- | lib/json/CHANGES.md | 4 | ||||
| -rw-r--r-- | lib/json/json.tm | 2 | ||||
| -rw-r--r-- | lib/uuid/CHANGES.md | 4 | ||||
| -rw-r--r-- | lib/uuid/uuid.tm | 4 |
6 files changed, 32 insertions, 20 deletions
diff --git a/lib/base64/CHANGES.md b/lib/base64/CHANGES.md index 42ae752c..6c67c96d 100644 --- a/lib/base64/CHANGES.md +++ b/lib/base64/CHANGES.md @@ -1,5 +1,9 @@ # Version History +## v1.1 + +Update syntax for Tomo. + ## v1.0 Initial version diff --git a/lib/base64/base64.tm b/lib/base64/base64.tm index bf512a83..f31cfbc5 100644 --- a/lib/base64/base64.tm +++ b/lib/base64/base64.tm @@ -33,28 +33,28 @@ lang Base64 dest := Int64(1) while src + 2 <= Int64(bytes.length) chunk24 := ( - (Int32(bytes[src]) <<< 16) or (Int32(bytes[src+1]) <<< 8) or Int32(bytes[src+2]) + (Int32(bytes[src]!) <<< 16) or (Int32(bytes[src+1]!) <<< 8) or Int32(bytes[src+2]!) ) src += 3 - output[dest] = _enc[1 + ((chunk24 >>> 18) and 0b111111)] - output[dest+1] = _enc[1 + ((chunk24 >>> 12) and 0b111111)] - output[dest+2] = _enc[1 + ((chunk24 >>> 6) and 0b111111)] - output[dest+3] = _enc[1 + (chunk24 and 0b111111)] + output[dest] = _enc[1 + ((chunk24 >>> 18) and 0b111111)]! + output[dest+1] = _enc[1 + ((chunk24 >>> 12) and 0b111111)]! + output[dest+2] = _enc[1 + ((chunk24 >>> 6) and 0b111111)]! + output[dest+3] = _enc[1 + (chunk24 and 0b111111)]! dest += 4 if src + 1 == bytes.length chunk16 := ( - (Int32(bytes[src]) <<< 8) or Int32(bytes[src+1]) + (Int32(bytes[src]!) <<< 8) or Int32(bytes[src+1]!) ) - output[dest] = _enc[1 + ((chunk16 >>> 10) and 0b11111)] - output[dest+1] = _enc[1 + ((chunk16 >>> 4) and 0b111111)] - output[dest+2] = _enc[1 + ((chunk16 <<< 2)and 0b111111)] + output[dest] = _enc[1 + ((chunk16 >>> 10) and 0b11111)]! + output[dest+1] = _enc[1 + ((chunk16 >>> 4) and 0b111111)]! + output[dest+2] = _enc[1 + ((chunk16 <<< 2)and 0b111111)]! output[dest+3] = _EQUAL_BYTE else if src == bytes.length - chunk8 := Int32(bytes[src]) - output[dest] = _enc[1 + ((chunk8 >>> 2) and 0b111111)] - output[dest+1] = _enc[1 + ((chunk8 <<< 4) and 0b111111)] + chunk8 := Int32(bytes[src]!) + output[dest] = _enc[1 + ((chunk8 >>> 2) and 0b111111)]! + output[dest+1] = _enc[1 + ((chunk8 <<< 4) and 0b111111)]! output[dest+2] = _EQUAL_BYTE output[dest+3] = _EQUAL_BYTE @@ -70,10 +70,10 @@ lang Base64 dest := Int64(1) while src + 3 <= Int64(bytes.length) chunk24 := ( - (Int32(_dec[1+bytes[src]]) <<< 18) or - (Int32(_dec[1+bytes[src+1]]) <<< 12) or - (Int32(_dec[1+bytes[src+2]]) <<< 6) or - Int32(_dec[1+bytes[src+3]]) + (Int32(_dec[1+bytes[src]!]!) <<< 18) or + (Int32(_dec[1+bytes[src+1]!]!) <<< 12) or + (Int32(_dec[1+bytes[src+2]!]!) <<< 6) or + Int32(_dec[1+bytes[src+3]!]!) ) src += 4 @@ -82,7 +82,7 @@ lang Base64 output[dest+2] = Byte(chunk24 and 0xFF) dest += 3 - while output[-1] == 0xFF + while output[-1]! == 0xFF output[] = output.to(-2) return output[] diff --git a/lib/json/CHANGES.md b/lib/json/CHANGES.md index 42ae752c..6c67c96d 100644 --- a/lib/json/CHANGES.md +++ b/lib/json/CHANGES.md @@ -1,5 +1,9 @@ # Version History +## v1.1 + +Update syntax for Tomo. + ## v1.0 Initial version diff --git a/lib/json/json.tm b/lib/json/json.tm index 8127ce52..ab9b95dd 100644 --- a/lib/json/json.tm +++ b/lib/json/json.tm @@ -79,7 +79,7 @@ enum JSON( string ++= esc pos += 2 else if m := text.matching_pattern($Pat/u{4 digit}/) - string ++= Text.from_codepoints([Int32.parse(m.captures[1])!]) + string ++= Text.from_codepoints([Int32.parse(m.captures[1]!)!]) pos += 1 + m.text.length else if remainder diff --git a/lib/uuid/CHANGES.md b/lib/uuid/CHANGES.md index 42ae752c..6c67c96d 100644 --- a/lib/uuid/CHANGES.md +++ b/lib/uuid/CHANGES.md @@ -1,5 +1,9 @@ # Version History +## v1.1 + +Update syntax for Tomo. + ## v1.0 Initial version diff --git a/lib/uuid/uuid.tm b/lib/uuid/uuid.tm index f2be618e..ebc52259 100644 --- a/lib/uuid/uuid.tm +++ b/lib/uuid/uuid.tm @@ -4,8 +4,8 @@ use time_v1.0 lang UUID func v4(-> UUID) # Random UUID bytes := &random.bytes(16) - bytes[7; unchecked] = 0x40 or (bytes[7; unchecked] and 0x0F) - bytes[9; unchecked] = (Byte(random.int8(0x8, 0xB)) << 4) or (bytes[9; unchecked] and 0x0F) + bytes[7] = 0x40 or (bytes[7]! and 0x0F) + bytes[9] = (Byte(random.int8(0x8, 0xB)) << 4) or (bytes[9]! and 0x0F) hex := "".join([b.hex() for b in bytes]) uuid := "$(hex.slice(1, 8))-$(hex.slice(9, 12))-$(hex.slice(13, 16))-$(hex.slice(17, -1))" return UUID.from_text(uuid) |
