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 COMMON_INTERFACES_OBJECTS_STRING_LINE_STRING_H 17 #define COMMON_INTERFACES_OBJECTS_STRING_LINE_STRING_H 18 19 #include "common_interfaces/objects/string/base_string_declare.h" 20 21 namespace common { 22 /* 23 +-----------------------------+ <-- offset 0 24 | BaseObject fields | 25 +-----------------------------+ <-- offset = BaseObjectSize() 26 | LengthAndFlags (uint32_t) | 27 +-----------------------------+ 28 | RawHashcode (uint32_t) | 29 +-----------------------------+ <-- offset = BaseString::SIZE 30 | String Data (UTF8/16) | <-- DATA_OFFSET = BaseString::SIZE 31 | ... | 32 +-----------------------------+ 33 */ 34 // The LineString abstract class captures sequential string values, only LineString can store chars data 35 class LineString : public BaseString { 36 public: 37 BASE_CAST_CHECK(LineString, IsLineString); 38 NO_MOVE_SEMANTIC_CC(LineString); 39 NO_COPY_SEMANTIC_CC(LineString); 40 41 static constexpr size_t ALIGNMENT_8_BYTES = 8; 42 static constexpr uint32_t MAX_LENGTH = (1 << 28) - 16; 43 static constexpr uint32_t INIT_LENGTH_TIMES = 4; 44 // DATA_OFFSET: the string data stored after the string header. 45 // Data can be stored in utf8 or utf16 form according to compressed bit. 46 static constexpr size_t DATA_OFFSET = BaseString::SIZE; // DATA_OFFSET equal to Empty String size 47 48 uint16_t *GetData() const; 49 50 template <bool verify = true> 51 uint16_t Get(int32_t index) const; 52 53 void Set(uint32_t index, uint16_t src); 54 55 void Trim(uint32_t newLength); 56 57 static size_t ComputeSizeUtf8(uint32_t utf8Len); 58 59 static size_t ComputeSizeUtf16(uint32_t utf16Len); 60 61 static size_t ObjectSize(BaseString *str); 62 63 static size_t DataSize(BaseString *str); 64 }; 65 } 66 #endif //COMMON_INTERFACES_OBJECTS_STRING_LINE_STRING_H