1 |
#Region "Microsoft.VisualBasic::460a32264abe004592333ff95f42667f, Microsoft.VisualBasic.Core\Serialization\JSON\Formatter\JsonFormatterInternal.vb"
|
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 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
#End Region
|
46 |
|
47 |
Imports System.Text
|
48 |
Imports Microsoft.VisualBasic.Serialization.JSON.Formatter.Internals.Strategies
|
49 |
|
50 |
Namespace Serialization.JSON.Formatter.Internals
|
51 |
|
52 |
Friend NotInheritable Class JsonFormatterInternal
|
53 |
|
54 |
ReadOnly context As JsonFormatterStrategyContext
|
55 |
|
56 |
Public Sub New(context As JsonFormatterStrategyContext)
|
57 |
Me.context = context
|
58 |
|
59 |
Me.context.ClearStrategies()
|
60 |
Me.context.AddCharacterStrategy(New OpenBracketStrategy())
|
61 |
Me.context.AddCharacterStrategy(New CloseBracketStrategy())
|
62 |
Me.context.AddCharacterStrategy(New OpenSquareBracketStrategy())
|
63 |
Me.context.AddCharacterStrategy(New CloseSquareBracketStrategy())
|
64 |
Me.context.AddCharacterStrategy(New SingleQuoteStrategy())
|
65 |
Me.context.AddCharacterStrategy(New DoubleQuoteStrategy())
|
66 |
Me.context.AddCharacterStrategy(New CommaStrategy())
|
67 |
Me.context.AddCharacterStrategy(New ColonCharacterStrategy())
|
68 |
Me.context.AddCharacterStrategy(New SkipWhileNotInStringStrategy(ControlChars.Lf))
|
69 |
Me.context.AddCharacterStrategy(New SkipWhileNotInStringStrategy(ControlChars.Cr))
|
70 |
Me.context.AddCharacterStrategy(New SkipWhileNotInStringStrategy(ControlChars.Tab))
|
71 |
Me.context.AddCharacterStrategy(New SkipWhileNotInStringStrategy(" "c))
|
72 |
End Sub
|
73 |
|
74 |
Public Function Format(json As String) As String
|
75 |
If json Is Nothing Then
|
76 |
Return String.Empty
|
77 |
End If
|
78 |
|
79 |
If json.Trim() = String.Empty Then
|
80 |
Return String.Empty
|
81 |
End If
|
82 |
|
83 |
Dim input As New StringBuilder(json)
|
84 |
Dim output As New StringBuilder()
|
85 |
|
86 |
Me.PrettyPrintCharacter(input, output)
|
87 |
|
88 |
Return output.ToString()
|
89 |
End Function
|
90 |
|
91 |
Private Sub PrettyPrintCharacter(input As StringBuilder, output As StringBuilder)
|
92 |
For i As Integer = 0 To input.Length - 1
|
93 |
Me.context.PrettyPrintCharacter(input(i), output)
|
94 |
Next
|
95 |
End Sub
|
96 |
End Class
|
97 |
End Namespace
|