diff options
author | Jere Käpyaho <2261936+jerekapyaho@users.noreply.github.com> | 2022-02-23 21:53:36 +0200 |
---|---|---|
committer | Jere Käpyaho <2261936+jerekapyaho@users.noreply.github.com> | 2022-02-23 21:55:53 +0200 |
commit | d431934b9cfd93f91fdc89a4e13a7a6c997dffd7 (patch) | |
tree | 7d7a50171d73feb9cf574f79c3b42fa6e2895df7 | |
parent | 21b2304a1f8ba43e9fbafd4881ac61d39ad49042 (diff) |
Added argument and source output for F# array, with example in README
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | src/lib.rs | 14 | ||||
-rw-r--r-- | src/main.rs | 4 |
3 files changed, 23 insertions, 4 deletions
@@ -191,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. @@ -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,17 @@ 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))?; + if array_format != "f" { + write!(locked, "{}", hex_lower_hex(*hex))?; + } else { + write!(locked, "{}uy", hex_lower_hex(*hex))?; + } } else { - write!(locked, "{}, ", hex_lower_hex(*hex))?; + if array_format != "f" { + write!(locked, "{}, ", hex_lower_hex(*hex))?; + } else { + write!(locked, "{}uy; ", hex_lower_hex(*hex))?; + } } } writeln!(locked)?; @@ -445,6 +454,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( |