2019-07-29 02:05:05 +08:00
|
|
|
|
#Region "Microsoft.VisualBasic::18caaeaecae432ae59ba5c9891b0b90d, Microsoft.VisualBasic.Core\Serialization\JSON\JsonFormatter.vb"
|
2019-06-04 20:43:55 +08:00
|
|
|
|
|
|
|
|
|
|
' Author:
|
|
|
|
|
|
'
|
|
|
|
|
|
' asuka (amethyst.asuka@gcmodeller.org)
|
|
|
|
|
|
' xie (genetics@smrucc.org)
|
|
|
|
|
|
' xieguigang (xie.guigang@live.com)
|
|
|
|
|
|
'
|
|
|
|
|
|
' Copyright (c) 2018 GPL3 Licensed
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' GNU GENERAL PUBLIC LICENSE (GPL3)
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
' it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
' the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
' (at your option) any later version.
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
' but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
' GNU General Public License for more details.
|
|
|
|
|
|
'
|
|
|
|
|
|
' You should have received a copy of the GNU General Public License
|
|
|
|
|
|
' along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
' /********************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
' Summaries:
|
|
|
|
|
|
|
|
|
|
|
|
' Module JsonFormatter
|
|
|
|
|
|
'
|
|
|
|
|
|
' Function: Format, Minify
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' /********************************************************************************/
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
|
|
|
|
Imports System.Text.RegularExpressions
|
|
|
|
|
|
Imports Microsoft.VisualBasic.Serialization.JSON.Formatter.Internals
|
2019-05-31 19:14:18 +08:00
|
|
|
|
Imports r = System.Text.RegularExpressions.Regex
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
Namespace Serialization.JSON.Formatter
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Provides JSON formatting functionality.
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
Public Module JsonFormatter
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Returns a 'pretty printed' version of the specified JSON string, formatted for human
|
|
|
|
|
|
''' consumption.
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <param name="json">A valid JSON string.</param>
|
|
|
|
|
|
''' <returns>A 'pretty printed' version of the specified JSON string.</returns>
|
|
|
|
|
|
Public Function Format(json As String) As String
|
|
|
|
|
|
Dim context As New JsonFormatterStrategyContext()
|
|
|
|
|
|
Dim formatter As New JsonFormatterInternal(context)
|
|
|
|
|
|
|
2019-05-31 19:14:18 +08:00
|
|
|
|
Return formatter.Format(json Or die("json should not be null."))
|
2018-08-02 20:14:48 +08:00
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Returns a 'minified' version of the specified JSON string, stripped of all
|
|
|
|
|
|
''' non-essential characters.
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <param name="json">A valid JSON string.</param>
|
|
|
|
|
|
''' <returns>A 'minified' version of the specified JSON string.</returns>
|
|
|
|
|
|
Public Function Minify(json As String) As String
|
2019-05-31 19:14:18 +08:00
|
|
|
|
Return r.Replace(json Or die("json should not be null."), "(""(?:[^""\\]|\\.)*"")|\s+", "$1")
|
2018-08-02 20:14:48 +08:00
|
|
|
|
End Function
|
|
|
|
|
|
End Module
|
|
|
|
|
|
End Namespace
|