-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJNumber.cls
More file actions
128 lines (113 loc) · 4 KB
/
JNumber.cls
File metadata and controls
128 lines (113 loc) · 4 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "JNumber"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'@Exposed
'@Folder "JSON"
Option Explicit
Private mData As JSON.StringStream
Private mNumber As Double
#If DEV Then
Private Const ModuleName As String = "JNumber"
#End If
'@Description "Constructor"
Friend Sub Create(ByVal StringStream As JSON.StringStream)
Attribute Create.VB_Description = "Constructor"
#If DEV Then
Debug.Assert Not (StringStream Is Nothing)
Const FunctionName As String = "Create"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Set mData = StringStream
Parse
End Sub
'@Description "Class's data type"
Public Function DataType() As JSON.JType
Attribute DataType.VB_Description = "Class's data type"
#If DEV Then
Const FunctionName As String = "DataType"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
DataType = JSON.JType.JSNumber
End Function
'@Description "Stream parsing"
Private Sub Parse()
Attribute Parse.VB_Description = "Stream parsing"
#If DEV Then
Const FunctionName As String = "Parse"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Dim Value As String
Value = mData.GetStringFromRegEx("^(?:-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)")
If (Value <> vbNullString) Then
mData.EatString Value
Else
Err.Raise JSON.JException.JUnexpectedToken, "JNumber.Parse", "Numeric character expected."
End If
On Error GoTo RegionalError
mNumber = CDbl(Value)
Exit Sub
regionalResume:
mNumber = CDbl(Value)
Exit Sub
RegionalError:
If (Err.Number = 13) Then '// Type mismatch due to regional settings
Value = Replace(Value, ".", ",")
End If
Err.Clear
GoTo regionalResume
End Sub
'@Description "Return the numeric value of the object."
Public Property Get Value() As Double
Attribute Value.VB_Description = "Return the numeric value of the object."
#If DEV Then
Const FunctionName As String = "Value (Get)"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Value = mNumber
End Property
'@Description "Set the numeric value of the object"
Public Property Let Value(ByVal Data As Double)
Attribute Value.VB_Description = "Set the numeric value of the object"
#If DEV Then
Const FunctionName As String = "Value (Let)"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
mNumber = Data
End Property
'@Description "return a JSON string representation of the object"
Public Function ToJSONString() As String
Attribute ToJSONString.VB_Description = "return a JSON string representation of the object"
#If DEV Then
Const FunctionName As String = "ToJSONString"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Dim Output As String
Output = ToString
Output = Replace(Output, ",", ".")
ToJSONString = Output
End Function
'@Description "Retrun a human readable string representation of the object"
Public Function ToString(Optional ByVal IndentMultiplier As Long = 0) As String
Attribute ToString.VB_Description = "Retrun a human readable string representation of the object"
#If DEV Then
Debug.Assert IndentMultiplier >= 0
Const FunctionName As String = "ToString"
Dim Logger As JSON.Logger
Set Logger = Services.CreateLogger(Services.LibraryName & "." & ModuleName, FunctionName)
#End If
Dim Output As String
Output = CStr(mNumber)
ToString = Output
End Function