1 /* 2 * Copyright (c) 2025 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_BUILTINS_GLOBAL_URI_INL_H 17 #define ECMASCRIPT_BUILTINS_GLOBAL_URI_INL_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/builtins/builtins_global.h" 21 #include "ecmascript/builtins/builtins_global_uri.h" 22 23 namespace panda::ecmascript::builtins { 24 IsUnescapedURI(uint16_t ch)25bool BuiltinsGlobal::IsUnescapedURI(uint16_t ch) 26 { 27 if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9')) { 28 return true; 29 } 30 return IsInMarkURISet(ch); 31 } 32 IsInUnescapedURISet(uint16_t ch)33bool BuiltinsGlobal::IsInUnescapedURISet(uint16_t ch) 34 { 35 if (ch == '#') { 36 return true; 37 } 38 return IsUnescapedURI(ch) || IsReservedURI(ch); 39 } 40 IsInReservedURISet(uint16_t ch)41bool BuiltinsGlobal::IsInReservedURISet(uint16_t ch) 42 { 43 if (ch == '#') { 44 return true; 45 } 46 return IsReservedURI(ch); 47 } 48 49 #if ENABLE_NEXT_OPTIMIZATION IsReservedURI(uint16_t ch)50bool BuiltinsGlobal::IsReservedURI(uint16_t ch) 51 { 52 if (ch == '@') { 53 return true; 54 } 55 56 if (ch > BITMAP_SIZE) { 57 return false; 58 } 59 60 return ((1ULL << ch) & RESERVED_URI_MASK) != 0; 61 } 62 IsInMarkURISet(uint16_t ch)63bool BuiltinsGlobal::IsInMarkURISet(uint16_t ch) 64 { 65 if (ch == '_' || ch == '~') { 66 return true; 67 } 68 69 if (ch > BITMAP_SIZE) { 70 return false; 71 } 72 73 return ((1ULL << ch) & MARK_URI_MASK) != 0; 74 } 75 #endif // ENABLE_NEXT_OPTIMIZATION 76 } // namespace panda::ecmascript::builtins 77 78 #endif // ECMASCRIPT_BUILTINS_GLOBAL_URI_INL_H