-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonNumber.cls
More file actions
100 lines (81 loc) · 2.88 KB
/
JsonNumber.cls
File metadata and controls
100 lines (81 loc) · 2.88 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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "JsonNumber"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'@Folder("JSON.Core")
Option Explicit
Implements IJson
Private Const ModuleName As String = "JsonNumber"
Private Type TData
Value As Double
End Type
Private This As TData
Friend Sub Create(ByVal Stream As StringStream)
Const FunctionName As String = "Create"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
Parse Stream
End Sub
Private Function IJson_DataType() As JsonDataTypeEnum
Const FunctionName As String = "IJson_DataType"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
IJson_DataType = JsonDataTypeNumber
End Function
Public Function DataType() As JsonDataTypeEnum
Const FunctionName As String = "DataType"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
DataType = IJson_DataType
End Function
Private Function IJson_ToString() As String
Const FunctionName As String = "IJson_ToString"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
IJson_ToString = Replace(CStr(This.Value), ",", ".")
End Function
Public Function ToString() As String
Const FunctionName As String = "ToString"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
ToString = IJson_ToString
End Function
'@DefaultMember
Public Function Value() As Double
Attribute Value.VB_UserMemId = 0
Const FunctionName As String = "Value"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
Value = This.Value
End Function
Private Sub Parse(ByVal Stream As StringStream)
Const FunctionName As String = "Parse"
Dim ErrorLogger As ErrorLogger
Set ErrorLogger = Factory.CreateErrorLogger(ModuleName, FunctionName)
Const Pattern As String = "^(?:-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)"
If (Stream.Match(Pattern)) Then
Dim Token As String
Token = Stream.PeekString(Pattern)
On Error GoTo RegionalSettingsError
This.Value = CDbl(Token)
On Error GoTo 0
Stream.EatString Token
Else
Err.Raise JsonExceptionUnexpectedToken, ModuleName & "." & FunctionName, "Numeric token expected."
End If
Exit Sub
RegionalSettingsError:
Select Case Err.Number
Case 13 '// Type mismatch due to regional settings
Err.Clear
This.Value = CDbl(Replace$(Token, ".", ","))
Resume Next
Case Else
Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End Select
End Sub