Skip to content

Commit

Permalink
Merge pull request #113
Browse files Browse the repository at this point in the history
  • Loading branch information
delasy authored Jan 13, 2025
2 parents c644ce5 + 1497cb9 commit c74a2ae
Show file tree
Hide file tree
Showing 103 changed files with 5,122 additions and 1,026 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ By participating in this project you agree to abide by its terms.
### On Unix

```shell
curl -fsSL https://cdn.thelang.io/cli | bash
curl -fsSL sh.thelang.io | bash
the run scripts/pre-process-codegen -o scripts/a.out
```

### On Windows

```powershell
(New-Object System.Net.WebClient).DownloadString('https://cdn.thelang.io/cli-win') | iex
irm ps1.thelang.io | iex
the run pre-process-codegen -o scripts/a.exe
```

Expand Down
71 changes: 70 additions & 1 deletion packages/algorithm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,57 @@ A string in ASCII format containing decoded data from `data`.
base64.decode("QWFyb24=")
```

### `byteArray.fromStr (in: str) byte[]`
Converts a string into a byte array.

**Parameters**

- `in` - string to convert

**Return value**

A byte array representing input string.

**Examples**

```the
byteArray.fromStr("Aaron")
```

### `byteArray.toHexStr (in: byte[]) str`
Converts a byte array into a hex string.

**Parameters**

- `in` - byte array to convert

**Return value**

A hex string representing input byte array.

**Examples**

```the
byteArray.toHexStr([0x41, 0x61, 0x72, 0x6F, 0x6E])
```

### `byteArray.toStr (in: byte[]) str`
Converts a byte array into a string.

**Parameters**

- `in` - byte array to convert

**Return value**

A string representing input byte array.

**Examples**

```the
byteArray.toStr([0x41, 0x61, 0x72, 0x6F, 0x6E])
```

### `qrcode.QRCode (input: Buffer) IQRCode`
Constructs `IQRCode` object.

Expand All @@ -62,7 +113,7 @@ Constructed `IQRCode` object.

**Exceptions**

- `Base64Error` - thrown if string to be decoded is not correctly encoded
- `QRCodeError` - thrown if string to be decoded is not correctly encoded

**Examples**

Expand Down Expand Up @@ -113,3 +164,21 @@ mut qr := qrcode.QRCode("HELLO, WORLD!")
qr.encode(ecc: .M, mask: 3)
qrcode.toTerminal(qr)
```

### `md5 (data: byte[]) byte[]`
Encodes byte array with md5 algorithm.

**Parameters**

- `data` - byte array to encode

**Return value**

A byte array containing md5 representation of the `data`.

**Examples**

```the
import byteArray, md5 from "the/algorithm"
result := md5(byteArray.fromStr("Aaron"))
```
35 changes: 35 additions & 0 deletions packages/algorithm/src/byte-array
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*!
* Copyright (c) Aaron Delasy
* Licensed under the MIT License
*/

const HEX_CHARS := ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]

export fn fromStr (in: str) byte[] {
mut result: byte[]
loop i := 0; i < in.len; i++ {
result.push(in[i].byte)
}
return result
}

export fn toHexStr (in: byte[]) str {
mut result := ""
loop i := 0; i < in.len; i++ {
b := in[i] as byte
i: int = b >> 4
j: int = b & 0x0F
result += HEX_CHARS[i]
result += HEX_CHARS[j]
}
return result
}

export fn toStr (in: byte[]) str {
mut result := ""
loop i := 0; i < in.len; i++ {
ch: char = in[i] as byte
result += ch.str()
}
return result
}
4 changes: 4 additions & 0 deletions packages/algorithm/src/main
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
*/

import * as base64 from "./base64"
import * as byteArray from "./byte-array"
import * as qrcode from "./qrcode"
import md5 from "./md5"

export base64
export byteArray
export qrcode
export md5
Loading

0 comments on commit c74a2ae

Please sign in to comment.