initial commits

master
Charles Iliya Krempeaux 2023-10-27 11:58:14 -07:00
parent d1077fe542
commit 269d4969a6
7 changed files with 53 additions and 33 deletions

View File

@ -1,5 +1,9 @@
package hexadeca
import (
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
)
// EncodeByte encodes the value of a byte into hexadecimal.
func EncodeByte(value byte, symbolFunc func(byte)rune) (mostSignificant rune, leastSignificant rune) {
@ -10,13 +14,13 @@ func EncodeByte(value byte, symbolFunc func(byte)rune) (mostSignificant rune, le
}
func EncodeByteUsingLowerCaseSymbols(value byte) (mostSignificant rune, leastSignificant rune) {
return EncodeByte(value, SymbolLowerCase)
return EncodeByte(value, runesymbols.LowerCase)
}
func EncodeByteUsingPersianSymbols(value byte) (mostSignificant rune, leastSignificant rune) {
return EncodeByte(value, SymbolLowerCase)
return EncodeByte(value, runesymbols.Persian)
}
func EncodeByteUsingUpperCaseSymbols(value byte) (mostSignificant rune, leastSignificant rune) {
return EncodeByte(value, SymbolUpperCase)
return EncodeByte(value, runesymbols.UpperCase)
}

View File

@ -1,5 +1,9 @@
package hexadeca
import (
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
)
func EncodeInt64(value int64, symbolFunc func(byte)rune) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
r15, r14 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 7))), symbolFunc)
r13, r12 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 6))), symbolFunc)
@ -14,13 +18,13 @@ func EncodeInt64(value int64, symbolFunc func(byte)rune) (r15 rune, r14 rune, r1
}
func EncodeInt64UsingLowerCaseSymbols(value int64) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeInt64(value, SymbolLowerCase)
return EncodeInt64(value, runesymbols.LowerCase)
}
func EncodeInt64UsingPersianSymbols(value int64) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeInt64(value, SymbolPersian)
return EncodeInt64(value, runesymbols.Persian)
}
func EncodeInt64UsingUpperCaseSymbols(value int64) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeInt64(value, SymbolUpperCase)
return EncodeInt64(value, runesymbols.UpperCase)
}

View File

@ -1,5 +1,9 @@
package hexadeca
import (
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
)
func EncodeUint16(value uint16, symbolFunc func(byte)rune) (r3 rune, r2 rune, r1 rune, r0 rune) {
r3, r2 = EncodeByte(byte(0x00ff & (value >> (8 ))), symbolFunc)
r1, r0 = EncodeByte(byte(0x00ff & value ), symbolFunc)
@ -8,13 +12,13 @@ func EncodeUint16(value uint16, symbolFunc func(byte)rune) (r3 rune, r2 rune, r1
}
func EncodeUint16UsingLowerCaseSymbols(value uint16) (r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint16(value, SymbolLowerCase)
return EncodeUint16(value, runesymbols.LowerCase)
}
func EncodeUint16UsingPersianSymbols(value uint16) (r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint16(value, SymbolPersian)
return EncodeUint16(value, runesymbols.Persian)
}
func EncodeUint16UsingUpperCaseSymbols(value uint16) (r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint16(value, SymbolUpperCase)
return EncodeUint16(value, runesymbols.UpperCase)
}

View File

@ -1,5 +1,9 @@
package hexadeca
import (
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
)
func EncodeUint32(value uint32, symbolFunc func(byte)rune) (r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
r7, r6 = EncodeByte(byte(0x000000ff & (value >> (8 * 3))), symbolFunc)
r5, r4 = EncodeByte(byte(0x000000ff & (value >> (8 * 2))), symbolFunc)
@ -10,13 +14,13 @@ func EncodeUint32(value uint32, symbolFunc func(byte)rune) (r7 rune, r6 rune, r5
}
func EncodeUint32UsingLowerCaseSymbols(value uint32) (r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint32(value, SymbolLowerCase)
return EncodeUint32(value, runesymbols.LowerCase)
}
func EncodeUint32UsingPersianSymbols(value uint32) (r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint32(value, SymbolPersian)
return EncodeUint32(value, runesymbols.Persian)
}
func EncodeUint32UsingUpperCaseSymbols(value uint32) (r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint32(value, SymbolUpperCase)
return EncodeUint32(value, runesymbols.UpperCase)
}

View File

@ -1,5 +1,9 @@
package hexadeca
import (
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
)
func EncodeUint64(value uint64, symbolFunc func(byte)rune) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
r15, r14 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 7))), symbolFunc)
r13, r12 = EncodeByte(byte(0x00000000000000ff & (value >> (8 * 6))), symbolFunc)
@ -14,13 +18,13 @@ func EncodeUint64(value uint64, symbolFunc func(byte)rune) (r15 rune, r14 rune,
}
func EncodeUint64UsingLowerCaseSymbols(value uint64) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint64(value, SymbolLowerCase)
return EncodeUint64(value, runesymbols.LowerCase)
}
func EncodeUint64UsingPersianSymbols(value uint64) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint64(value, SymbolPersian)
return EncodeUint64(value, runesymbols.Persian)
}
func EncodeUint64UsingUpperCaseSymbols(value uint64) (r15 rune, r14 rune, r13 rune, r12 rune, r11 rune, r10 rune, r9 rune, r8 rune, r7 rune, r6 rune, r5 rune, r4 rune, r3 rune, r2 rune, r1 rune, r0 rune) {
return EncodeUint64(value, SymbolUpperCase)
return EncodeUint64(value, runesymbols.UpperCase)
}

View File

@ -1,34 +1,34 @@
package hexadeca
package runesymbols
import (
"sourcecode.social/reiver/go-hexadeca/symbols/byte"
)
// SymbolLowerCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using lower-case symbols from ASCII / Unicode UTF-8.
// LowerCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using lower-case symbols from ASCII / Unicode UTF-8.
// I.e.,
//
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
//
// Example usage:
//
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, hexadeca.SymbolLowerCase)
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, runesymbols.LowerCase)
//
// If value was 254 (== 0xFE) then mostSignificiant would be 'f' and and leastSignificant would be 'e'.
func SymbolLowerCase(value byte) rune {
func LowerCase(value byte) rune {
return rune(bytesymbols.LowerCase(value))
}
// SymbolPersian is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using Persian symbols from Unicode UTF-8.
// Persian is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using Persian symbols from Unicode UTF-8.
// I.e.,
//
// '۰' (zero), '۱' (one), '۲' (two), '۳' (three), '۴' (four), '۵' (five), '۶' (six), '۷' (seven), '۸' (eight) ,'۹' (nine), 'ا' (alef), 'ب ' (be), 'پ ' (pe), 'ت ' (te), 'ث ' (s̱e), 'ج' (jim)
//
// Example usage:
//
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, hexadeca.SymbolPersian)
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, runesymbols.Persian)
//
// If value was 90 (== 0x5A) then mostSignificiant would be '۵' and and leastSignificant would be '\u0627'.
func SymbolPersian(value byte) rune {
func Persian(value byte) rune {
var table [16]rune = [16]rune{
'\u06F0', // ۰ (zero)
'\u06F1', // ۱ (one)
@ -55,16 +55,16 @@ func SymbolPersian(value byte) rune {
return result
}
// SymbolUpperCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using upper-case symbols from ASCII / Unicode UTF-8.
// UpperCase is used with hexadeca.EncodeByte() to encode a byte into hexadecimal symbols using upper-case symbols from ASCII / Unicode UTF-8.
// I.e.,
//
// '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
//
// Example usage:
//
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, hexadeca.SymbolUpperCase)
// mostSignificiant, leastSignificant := hexadeca.EncodeByte(value, runesymbols.UpperCase)
//
// If value was 254 (== 0xFE) then mostSignificiant would be 'F' and and leastSignificant would be 'E'.
func SymbolUpperCase(value byte) rune {
func UpperCase(value byte) rune {
return rune(bytesymbols.UpperCase(value))
}

View File

@ -1,12 +1,12 @@
package hexadeca_test
package runesymbols_test
import (
"testing"
"sourcecode.social/reiver/go-hexadeca"
"sourcecode.social/reiver/go-hexadeca/symbols/rune"
)
func TestSymbolLowerCase(t *testing.T) {
func TestLowerCase(t *testing.T) {
tests := []struct{
Value byte
@ -80,7 +80,7 @@ func TestSymbolLowerCase(t *testing.T) {
for testNumber, test := range tests {
actual := hexadeca.SymbolLowerCase(test.Value)
actual := runesymbols.LowerCase(test.Value)
expected := test.Expected
if expected != actual {
@ -94,7 +94,7 @@ func TestSymbolLowerCase(t *testing.T) {
}
}
func TestSymbolPersian(t *testing.T) {
func TestPersian(t *testing.T) {
tests := []struct{
Value byte
@ -168,7 +168,7 @@ func TestSymbolPersian(t *testing.T) {
for testNumber, test := range tests {
actual := hexadeca.SymbolPersian(test.Value)
actual := runesymbols.Persian(test.Value)
expected := test.Expected
if expected != actual {
@ -182,7 +182,7 @@ func TestSymbolPersian(t *testing.T) {
}
}
func TestSymbolUpperCase(t *testing.T) {
func TestUpperCase(t *testing.T) {
tests := []struct{
Value byte
@ -256,7 +256,7 @@ func TestSymbolUpperCase(t *testing.T) {
for testNumber, test := range tests {
actual := hexadeca.SymbolUpperCase(test.Value)
actual := runesymbols.UpperCase(test.Value)
expected := test.Expected
if expected != actual {