Skip to content

Commit

Permalink
Merge pull request #52 from jerekapyaho/swift-array
Browse files Browse the repository at this point in the history
Add Swift array support
  • Loading branch information
sitkevij authored Feb 19, 2021
2 parents d7d381f + 281d3b4 commit 5097454
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ cat README.md | docker run -i sitkevij/hx:latest

## features

### output arrays in `rust`, `c`, `golang`, `python`, `kotlin`, or `java`
### output arrays in `rust`, `c`, `golang`, `python`, `kotlin`, `java`, or `swift`

`hx` has a feature which can output the input file bytes as source code arrays.

Expand Down Expand Up @@ -164,6 +164,15 @@ byte[] a = new byte[]{
};
```

#### swift array: -as

```sh
$ hx -as -c8 tests/files/tiny.txt
let a: [UInt8] = [
0x69, 0x6c, 0x0a
]
```

### NO_COLOR support

`hx` will honor the NO_COLOR environment variable. If set, no color will be output to the terminal.
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ pub fn output_array(
"p" => writeln!(locked, "a = [")?,
"k" => writeln!(locked, "val a = byteArrayOf(")?,
"j" => writeln!(locked, "byte[] a = new byte[]{{")?,
"s" => writeln!(locked, "let a: [UInt8] = [")?,
_ => writeln!(locked, "unknown array format")?,
}
let mut i: u64 = 0x0;
Expand All @@ -424,6 +425,7 @@ pub fn output_array(
"g" => "}",
"p" => "]",
"k" => ")",
"s" => "]",
_ => "unknown array format",
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ fn main() {
.short("a")
.long(ARG_ARR)
.value_name("array_format")
.help("Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j)")
.possible_values(&["r", "c", "g", "p", "k", "j"])
.help("Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j), swift (s)")
.possible_values(&["r", "c", "g", "p", "k", "j", "s"])
.takes_value(true),
)
.arg(
Expand Down

0 comments on commit 5097454

Please sign in to comment.