blob: a5393aa7ddc8a5443ee3cab0ff28d22f58d1c095 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package utils
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)
}
|