Skip to content

Commit 9311321

Browse files
Bikramjeet Vigfacebook-github-bot
Bikramjeet Vig
authored andcommitted
misc(json): Add jsoncons as a vendored library (facebookincubator#12406)
Summary: Pull Request resolved: facebookincubator#12406 This is part of an effort to add support for complete set of json path tokens. As a first step we add jsoncons as a vendored library and in the upcoming changes we will start to incrementally use it. The code for the library has been pulled from https://github.com/danielaparker/jsoncons with some changes. The changes include: - Only files relevant to json and json parsing have been included - The #include directives have been updated to point to local paths - Prepend Apache license while preserving the existing boost license - The namespaces have been prepended with facebook::velox to avoid namespace conflict if velox is included in projects that already use jsoncons - Made changes to the json path parser to conform with jayway library which is a json library currently used by presto java. - Added a flag to the json path parser that returns an error for paths not currently supported by velox. Changes made to the parser include: - Added support for unquoted identifier after bracket `$[<identifier>]` that can also start with a number like `$[Key]` or `$[30day]` - Added support for bracket (`[`) after dot `$.['key']` (redundant use of dot operator) - Added support for dash (`-`) in the middle of an unquoted string - Added support for prepending by default `$.` in not included at the beginning of the path. This is to support cases like `[0]` or `key` which will now be equivalent to `$.[0]` or `$.key` Reviewed By: xiaoxmeng Differential Revision: D68564596
1 parent 88a05e3 commit 9311321

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+49271
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// Copyright 2013-2025 Daniel Parker
17+
// Distributed under the Boost license, Version 1.0.
18+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
19+
20+
// See https://github.com/danielaparker/jsoncons for latest version
21+
22+
#ifndef JSONCONS_ALLOCATOR_HOLDER_HPP
23+
#define JSONCONS_ALLOCATOR_HOLDER_HPP
24+
25+
namespace facebook::velox::jsoncons {
26+
27+
template <typename Allocator>
28+
class allocator_holder
29+
{
30+
public:
31+
using allocator_type = Allocator;
32+
private:
33+
allocator_type alloc_;
34+
public:
35+
allocator_holder() = default;
36+
allocator_holder(const allocator_holder&) = default;
37+
allocator_holder(allocator_holder&&) = default;
38+
allocator_holder& operator=(const allocator_holder&) = delete;
39+
allocator_holder(const allocator_type& alloc)
40+
: alloc_(alloc)
41+
{}
42+
~allocator_holder() = default;
43+
44+
allocator_type get_allocator() const
45+
{
46+
return alloc_;
47+
}
48+
};
49+
50+
} // namespace facebook::velox::jsoncons
51+
52+
#endif // JSONCONS_ALLOCATOR_HOLDER_HPP
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
// Copyright 2013-2025 Daniel Parker
17+
// Distributed under the Boost license, Version 1.0.
18+
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
19+
20+
// See https://github.com/danielaparker/jsoncons for latest version
21+
22+
#ifndef JSONCONS_ALLOCATOR_SET_HPP
23+
#define JSONCONS_ALLOCATOR_SET_HPP
24+
25+
#include <memory>
26+
27+
#include "velox/external/jsoncons/tag_type.hpp"
28+
29+
namespace facebook::velox::jsoncons {
30+
31+
template <typename Allocator,typename TempAllocator >
32+
class allocator_set
33+
{
34+
Allocator result_alloc_;
35+
TempAllocator temp_alloc_;
36+
public:
37+
using allocator_type = Allocator;
38+
using temp_allocator_type = TempAllocator;
39+
40+
allocator_set(const Allocator& alloc=Allocator(),
41+
const TempAllocator& temp_alloc=TempAllocator())
42+
: result_alloc_(alloc), temp_alloc_(temp_alloc)
43+
{
44+
}
45+
46+
allocator_set(const allocator_set&) = default;
47+
allocator_set(allocator_set&&) = default;
48+
allocator_set& operator=(const allocator_set&) = delete;
49+
allocator_set& operator=(allocator_set&&) = delete;
50+
~allocator_set() = default;
51+
52+
Allocator get_allocator() const {return result_alloc_;}
53+
TempAllocator get_temp_allocator() const {return temp_alloc_;}
54+
};
55+
56+
inline
57+
allocator_set<std::allocator<char>,std::allocator<char>> combine_allocators()
58+
{
59+
return allocator_set<std::allocator<char>,std::allocator<char>>(std::allocator<char>(), std::allocator<char>());
60+
}
61+
62+
template <typename Allocator>
63+
allocator_set<Allocator,std::allocator<char>> combine_allocators(const Allocator& alloc)
64+
{
65+
return allocator_set<Allocator,std::allocator<char>>(alloc, std::allocator<char>());
66+
}
67+
68+
template <typename Allocator,typename TempAllocator >
69+
allocator_set<Allocator,TempAllocator> combine_allocators(const Allocator& alloc, const TempAllocator& temp_alloc)
70+
{
71+
return allocator_set<Allocator,TempAllocator>(alloc, temp_alloc);
72+
}
73+
74+
template <typename TempAllocator >
75+
allocator_set<std::allocator<char>,TempAllocator> temp_allocator_only(const TempAllocator& temp_alloc)
76+
{
77+
return allocator_set<std::allocator<char>,TempAllocator>(std::allocator<char>(), temp_alloc);
78+
}
79+
80+
} // namespace facebook::velox::jsoncons
81+
82+
#endif // JSONCONS_ALLOCATOR_SET_HPP

0 commit comments

Comments
 (0)