mirror of
https://github.com/Kindelia/Kind2.git
synced 2024-10-26 16:20:40 +03:00
Add/improve function "show"
This commit is contained in:
parent
ce3a246cd7
commit
2341e36255
2
base/Bits/show_reverse.kind
Normal file
2
base/Bits/show_reverse.kind
Normal file
@ -0,0 +1,2 @@
|
||||
Bits.show_reverse(bits: Bits): String
|
||||
Bits.show(Bits.reverse(bits))
|
15
base/Bits/to_buf_string.kind
Normal file
15
base/Bits/to_buf_string.kind
Normal file
@ -0,0 +1,15 @@
|
||||
// Show pairs of hex values ignoring "00"
|
||||
Bits.to_buf_string(x: Bits): String
|
||||
let full = Bits.to_hex_string(x)
|
||||
Bits.to_buf_string.clean(String.reverse(full), "")
|
||||
|
||||
Bits.to_buf_string.clean(xs: String, str: String): String
|
||||
case xs {
|
||||
nil : str
|
||||
cons:
|
||||
let {val, res} = String.take_pair(2, xs)
|
||||
let new = String.concat(
|
||||
if String.eql(val, "00") then "" else " " | val,
|
||||
str)
|
||||
Bits.to_buf_string.clean(res, new)
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
Buffer32.show(buf: Buffer32): String
|
||||
let str = "<Buffer32 "
|
||||
let str = "<Buffer32"
|
||||
for i: U32 from 0 to Nat.to_u32(buf@depth) with str:
|
||||
let crunk = Buffer32.get(i, buf)// group of 4 bytes
|
||||
let bits = U32.to_bits(crunk)
|
||||
let hex = Bits.to_hex_string(bits)
|
||||
let crunk = Buffer32.get(i, buf) // group of 4 bytes
|
||||
let bits = U32.to_bits(crunk)
|
||||
let hex = Bits.to_buf_string(bits)
|
||||
str | " " | hex
|
||||
str | " >"
|
||||
str | ">"
|
7
base/Buffer8/show.kind
Normal file
7
base/Buffer8/show.kind
Normal file
@ -0,0 +1,7 @@
|
||||
Buffer8.show(buf: Buffer8): String
|
||||
let str = "<Buffer8 "
|
||||
for i from 0 to buf@depth with str:
|
||||
let bits = U32.to_bits(Buffer32.get(i, buf)) // group of 4 bytes
|
||||
let hex = Bits.to_hex_string(bits)
|
||||
str | " " | hex
|
||||
str | " >"
|
12
base/String/take_pair.kind
Normal file
12
base/String/take_pair.kind
Normal file
@ -0,0 +1,12 @@
|
||||
String.take_pair(n: Nat, xs: String): Pair<String, String>
|
||||
String.take_pair.go(n, xs, "")
|
||||
|
||||
String.take_pair.go(n: Nat, xs: String, take_aux: String): Pair<String, String>
|
||||
case xs {
|
||||
nil : {take_aux, xs}
|
||||
cons: case n {
|
||||
zero : {take_aux, xs}
|
||||
succ:
|
||||
String.take_pair.go(n.pred, xs.tail, String.cons(xs.head, take_aux))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user