summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsitkevij <1553398+sitkevij@users.noreply.github.com>2022-05-01 11:17:52 -0700
committerGitHub <noreply@github.com>2022-05-01 11:17:52 -0700
commit2349e7fe145a1ab73ad91fb7535ec645389c889a (patch)
tree85a4ef78e7e0b7b77e659ccac1343aed76b25122
parentaa5e279a0ef1e394f8e2ca1ca42577ce65e3fa92 (diff)
parent8b1444fabc77517672d1ec8bcfab9405bc3ee020 (diff)
Merge pull request #68 from jerekapyaho/fsharp-array
Generate source code for F# arrays
-rw-r--r--README.md21
-rw-r--r--src/lib.rs12
-rw-r--r--src/main.rs4
3 files changed, 33 insertions, 4 deletions
diff --git a/README.md b/README.md
index 485074e..d8974ef 100644
--- a/README.md
+++ b/README.md
@@ -102,6 +102,18 @@ pacman -S hex
curl -sLO https://github.com/sitkevij/hex/releases/download/v0.4.2/hx_0.4.2_amd64.deb && dpkg -i hx_0.4.2_amd64.deb
```
+### guix install
+
+```sh
+guix install hex
+```
+
+In an isolated environment:
+
+```sh
+guix shell --container hex
+```
+
### docker run
```sh
@@ -179,6 +191,15 @@ let a: [UInt8] = [
]
```
+#### fsharp array: -af
+
+```sh
+$ hx -af -c8 tests/files/tiny.txt
+let a = [|
+ 0x69uy; 0x6cuy; 0x0auy
+|]
+```
+
### NO_COLOR support
`hx` will honor the NO_COLOR environment variable. If set, no color will be output to the terminal.
diff --git a/src/lib.rs b/src/lib.rs
index 8c2cda0..e51b120 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -419,6 +419,7 @@ pub fn output_array(
"k" => writeln!(locked, "val a = byteArrayOf(")?,
"j" => writeln!(locked, "byte[] a = new byte[]{{")?,
"s" => writeln!(locked, "let a: [UInt8] = [")?,
+ "f" => writeln!(locked, "let a = [|")?,
_ => writeln!(locked, "unknown array format")?,
}
let mut i: u64 = 0x0;
@@ -427,9 +428,15 @@ pub fn output_array(
for hex in line.hex_body.iter() {
i += 1;
if i == page.bytes && array_format != "g" {
- write!(locked, "{}", hex_lower_hex(*hex))?;
- } else {
+ if array_format != "f" {
+ write!(locked, "{}", hex_lower_hex(*hex))?;
+ } else {
+ write!(locked, "{}uy", hex_lower_hex(*hex))?;
+ }
+ } else if array_format != "f" {
write!(locked, "{}, ", hex_lower_hex(*hex))?;
+ } else {
+ write!(locked, "{}uy; ", hex_lower_hex(*hex))?;
}
}
writeln!(locked)?;
@@ -445,6 +452,7 @@ pub fn output_array(
"p" => "]",
"k" => ")",
"s" => "]",
+ "f" => "|]",
_ => "unknown array format",
}
)
diff --git a/src/main.rs b/src/main.rs
index 3fc5972..81313f0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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), swift (s)")
- .possible_values(&["r", "c", "g", "p", "k", "j", "s"])
+ .help("Set source code format output: rust (r), C (c), golang (g), python (p), kotlin (k), java (j), swift (s), fsharp (f)")
+ .possible_values(&["r", "c", "g", "p", "k", "j", "s", "f"])
.takes_value(true),
)
.arg(