• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_BASE_JSON_HELPER_H
17 #define ECMASCRIPT_BASE_JSON_HELPER_H
18 
19 #include "ecmascript/js_handle.h"
20 #include "ecmascript/mem/c_string.h"
21 #include "ecmascript/property_attributes.h"
22 
23 namespace panda::ecmascript::base {
24 
25 class JsonHelper {
26 public:
27     static CString ValueToQuotedString(CString str);
28 
29     static bool IsFastValueToQuotedString(const char *value);
30 
CompareKey(const std::pair<JSHandle<JSTaggedValue>,PropertyAttributes> & a,const std::pair<JSHandle<JSTaggedValue>,PropertyAttributes> & b)31     static inline bool CompareKey(const std::pair<JSHandle<JSTaggedValue>, PropertyAttributes> &a,
32                                   const std::pair<JSHandle<JSTaggedValue>, PropertyAttributes> &b)
33     {
34         return a.second.GetDictionaryOrder() < b.second.GetDictionaryOrder();
35     }
36 
CompareNumber(const JSHandle<JSTaggedValue> & a,const JSHandle<JSTaggedValue> & b)37     static inline bool CompareNumber(const JSHandle<JSTaggedValue> &a, const JSHandle<JSTaggedValue> &b)
38     {
39         return a->GetNumber() < b->GetNumber();
40     }
41 };
42 
43 }  // namespace panda::ecmascript::base
44 
45 #endif  // ECMASCRIPT_BASE_UTF_JSON_H