Skip to content

Commit

Permalink
Preserve Unicode in JSON conversion
Browse files Browse the repository at this point in the history
Unicode text should be saved as Unicode in saved Json files.
Closes #30
  • Loading branch information
joyfullservice committed May 25, 2020
1 parent 61f574f commit f9859d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Version Control.accda.src/modules/clsOptions.bas
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,7 @@ Private Sub Class_Initialize()
' Load default values
Me.LoadDefaults

' Other run-time options
JsonOptions.AllowUnicodeChars = True

End Sub
10 changes: 9 additions & 1 deletion Version Control.accda.src/modules/modJsonConverter.bas
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ Private Type json_Options

' The solidus (/) is not required to be escaped, use this option to escape them as \/ in ConvertToJson
EscapeSolidus As Boolean

' Allow Unicode characters in JSON text. Set to True to use native Unicode or false for escaped values.
AllowUnicodeChars As Boolean
End Type
Public JsonOptions As json_Options

Expand Down Expand Up @@ -724,9 +727,14 @@ Private Function json_Encode(ByVal json_Text As Variant) As String
Case 9
' tab -> 9 -> \t
json_Char = "\t"
Case 0 To 31, 127 To 65535
Case 0 To 31
' Non-ascii characters -> convert to 4-digit hex
json_Char = "\u" & VBA.Right$("0000" & VBA.Hex$(json_AscCode), 4)
Case 127 To 65535
' Unicode character range
If Not JsonOptions.AllowUnicodeChars Then
json_Char = "\u" & VBA.Right$("0000" & VBA.Hex$(json_AscCode), 4)
End If
End Select

json_BufferAppend json_Buffer, json_Char, json_BufferPosition, json_BufferLength
Expand Down

0 comments on commit f9859d7

Please sign in to comment.