Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
202 lines (169 loc) · 6.38 KB

File metadata and controls

202 lines (169 loc) · 6.38 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* jsonata-cpp is the JSONata C++ reference port
*
* Copyright Dashjoin GmbH. https://dashjoin.com
* Copyright Robert Yokota
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <any>
#include <ctime>
#include <functional>
#include <limits>
#include <memory>
#include <optional>
#include <sstream>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <vector>
namespace jsonata {
// Cross-platform UTC time conversion: timegm on POSIX, _mkgmtime on Windows
static inline std::time_t timegm_utc(std::tm* tm) {
#if defined(_WIN32)
return _mkgmtime(tm);
#else
return timegm(tm);
#endif
}
// Forward declarations
class JFunction;
class JFunctionCallable;
class Utils {
public:
// Sentinel type to represent a JSON null literal (distinct from undefined)
class NullValue {};
// Unified list type that can represent either a regular list or a range
// (declared first for use in function signatures)
class JList : public std::vector<std::any> {
private:
// Range-specific members
int64_t range_start_ = 0;
int64_t range_end_ = 0;
bool is_range_ = false;
public:
// Regular list constructors
JList() : std::vector<std::any>() {}
JList(size_t capacity) : std::vector<std::any>() {
this->reserve(capacity);
}
JList(const std::vector<std::any>& other)
: std::vector<std::any>(other) {}
JList(const JList& other);
// Add initializer list constructor
JList(std::initializer_list<std::any> init)
: std::vector<std::any>(init),
range_start_(0),
range_end_(0),
is_range_(false) {}
// Range constructor
JList(int64_t start, int64_t end);
// JSONata specific flags
bool sequence = false;
bool outerWrapper = false;
bool tupleStream = false;
bool keepSingleton = false;
bool cons = false;
// Range detection
bool isRange() const { return is_range_; }
// Range-specific methods
int64_t getRangeStart() const { return range_start_; }
int64_t getRangeEnd() const { return range_end_; }
// Override size() for ranges
size_t size() const;
// Override operator[] for ranges (const)
std::any operator[](size_t index) const;
// Provide non-const operator[] so assignments work; materialize ranges
// on demand
std::any& operator[](size_t index);
// Override at() for ranges (const)
std::any at(size_t index) const;
// Provide non-const at() so assignments work; materialize ranges on
// demand
std::any& at(size_t index);
// Override empty() for ranges
bool empty() const;
// Range iterator support
class range_iterator {
private:
int64_t current_;
public:
range_iterator(int64_t val) : current_(val) {}
std::any operator*() const;
range_iterator& operator++();
bool operator!=(const range_iterator& other) const;
bool operator==(const range_iterator& other) const;
};
// For ranges, we need special iterator handling
range_iterator range_begin() const;
range_iterator range_end() const;
// Simple solution: Override begin/end to materialize ranges when needed
// for iteration This is simpler than complex custom iterators and
// ensures compatibility
using base_iterator = typename std::vector<std::any>::iterator;
using base_const_iterator =
typename std::vector<std::any>::const_iterator;
// Override begin/end to handle ranges by materializing if needed
base_iterator begin();
base_iterator end();
base_const_iterator begin() const;
base_const_iterator end() const;
base_const_iterator cbegin() const;
base_const_iterator cend() const;
private:
// If this list represents a range, materialize it into a concrete
// vector
void materializeRangeIfNeeded();
};
// Type alias for backward compatibility
using RangeList = JList;
// Type checking utilities
static bool isNumeric(const std::any& v);
static bool isIntegral(const std::any& v);
static bool isArrayOfStrings(const std::any& v);
static bool isArrayOfNumbers(const std::any& v);
static bool isFunction(const std::any& o);
// Numeric coercions
static int64_t toLong(const std::any& v);
static double toDouble(const std::any& v);
// General JSONata type checks (moved from Functions)
static bool isPrimitive(const std::any& value);
static bool isNumber(const std::any& value);
static bool isString(const std::any& value);
static bool isArray(const std::any& value);
static bool isObject(const std::any& value);
static bool isBoolean(const std::any& value);
static bool isNull(const std::any& value);
static bool isNullValue(const std::any& value);
static std::optional<std::string> type(const std::any& value);
// Sequence and list utilities
static JList createSequence();
static JList createSequence(const std::any& el);
// Utility functions
static bool isSequence(const std::any& result);
static std::any convertNumber(const std::any& n);
static JList arrayify(const std::any& value);
static void checkUrl(const std::string& str);
static std::any convertValue(const std::any& val);
static std::any convertNulls(const std::any& res);
static void quote(const std::string& string, std::ostringstream& w);
// Special values
static const std::any NONE;
static const std::any NULL_VALUE;
private:
static void convertNullsMap(std::any& res);
static void convertNullsList(std::any& res);
static void recurse(std::any& val);
};
} // namespace jsonata
Morty Proxy This is a proxified and sanitized view of the page, visit original site.