Public Sub ReadUTF8Map(Dir As String, FileName As String) As Map
If Not(File.Exists(Dir, FileName)) Then Return Null
Dim mapResult As Map : mapResult.Initialize
Dim lstLines As List = File.ReadList(Dir, FileName)
Dim LineTexts(2) As String
Dim Line As String
Dim LineFirstChar As String
Dim EqualCharPos As Int
For i = 0 To lstLines.Size -1
Line = lstLines.Get(i)
Log(Line)
Line = UnescapeUnicode(Line) ' <--- Error
Log(Line)
LineFirstChar = Line.SubString2(i, i + 1)
If LineFirstChar <> "#" AND LineFirstChar <> "!" Then ' if it is not a comment line
' LineTexts = Regex.Split(Line, "=") ' this does not work
EqualCharPos = Line.IndexOf("=")
LineTexts(0) = Line.SubString2(0, EqualCharPos)
LineTexts(1) = Line.SubString(EqualCharPos + 1)
mapResult.Put(LineTexts(0), LineTexts(1))
End If
Next
Return mapResult
End Sub
Public Sub UnescapeUnicode(s As String) As String
Dim sb As StringBuilder
sb.Initialize
Dim i As Int
Do While i < s.Length
Dim c As Char = s.CharAt(i)
If c = "\" AND i < s.Length - 1 AND s.CharAt(i + 1) = "u" Then
Dim unicode As StringBuilder
unicode.Initialize
i = i + 2
Do While i < s.Length
Dim cc As String = s.CharAt(i)
Dim n As Int = Asc(cc.ToLowerCase)
If (n >= Asc("0") AND n <= Asc("9")) OR (n >= Asc("a") AND n <= Asc("z")) Then
unicode.Append(s.CharAt(i))
Else
i = i - 1
Exit
End If
i = i + 1
Loop
sb.Append(Chr(Bit.ParseInt(unicode.ToString, 16)))
Else
sb.Append(c)
End If
i = i + 1
Loop
Return sb.ToString
End Sub