diff options
| author | Fuwn <[email protected]> | 2021-07-05 18:15:40 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-07-05 18:15:40 -0700 |
| commit | a7587a06445a7852e6931d807b885cc5d3227fd3 (patch) | |
| tree | 80ca884c63d796957d75d2c214836cf0f9390b9e /pkg/utilities | |
| parent | refactor(discord): move prefix to config file (diff) | |
| download | munch-a7587a06445a7852e6931d807b885cc5d3227fd3.tar.xz munch-a7587a06445a7852e6931d807b885cc5d3227fd3.zip | |
refactor(utilities): move utilities to seperate package
Diffstat (limited to 'pkg/utilities')
| -rw-r--r-- | pkg/utilities/hex.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/utilities/hex.go b/pkg/utilities/hex.go new file mode 100644 index 0000000..30428b7 --- /dev/null +++ b/pkg/utilities/hex.go @@ -0,0 +1,31 @@ +package utilities + +import "unicode/utf8" + +// https://stackoverflow.com/a/43461796/14452787 +// +// I cannot explain the joy that flew through me once I found this ISO-8859-1 +// (Latin-1) to UTF-8 converter. I was looking for a valid solution on how to +// insert the username and password into a hex-escaped string sequence for +// EncodeSessionInitialization for hours and this finally solved all of my +// problems. +func ISO88591ToString(iso string) string { + var utf []rune + for i := 0; i < len(iso); i++ { + r := iso[i] + if utf == nil { + if r < utf8.RuneSelf { + continue + } + utf = make([]rune, len(iso)) + for j, r := range iso[:i] { + utf[j] = rune(r) + } + } + utf[i] = rune(r) + } + if utf == nil { + return string(iso) + } + return string(utf) +} |