1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COMMON_LAYOUT_TEMPLATES_PARSER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COMMON_LAYOUT_TEMPLATES_PARSER_H 18 19 #include "base/utils/noncopyable.h" 20 #include "base/geometry/dimension.h" 21 #include "core/pipeline/base/render_node.h" 22 23 namespace OHOS::Ace { 24 class TemplatesParser final : public NonCopyable { 25 public: 26 TemplatesParser() = default; 27 ~TemplatesParser() override = default; TemplatesParser(const WeakPtr<RenderNode> & renderNode)28 explicit TemplatesParser(const WeakPtr<RenderNode>& renderNode) : renderNode_(renderNode) {} 29 30 std::vector<double> ParseArgs(const WeakPtr<RenderNode>& node, const std::string& args, double size, double gap); 31 32 private: 33 enum class RepeatType { 34 NONE = 0, 35 FIXED_COUNT, 36 AUTO_FILL, 37 }; 38 39 using Value = struct { 40 std::string str; 41 bool isRepeat = false; 42 }; 43 44 static void RTrim(std::string& str); 45 static std::string TrimTemplate(std::string& str); 46 static std::string GetRepeat(const std::string& str); 47 double ParseUnit(const Value& val, double size); 48 49 static void ConvertRepeatArgs(std::string& handledArg); 50 static std::vector<double> ParseArgs(const std::string& args, double size, double gap); 51 static std::vector<double> ParseAutoFill(const std::vector<std::string>& strs, double size, double gap); 52 53 double ConvertVirtualSize(const std::string& val, const DimensionUnit& unit, double size); 54 static bool SplitTemplate(const std::string& str, std::vector<Value>& vec, bool isRepeat = false); 55 std::vector<double> ParseArgsWithAutoFill(const std::string& args, double size, double gap); 56 static bool CheckRepeatAndSplitString( 57 std::vector<std::string>& vec, std::string& repeat, std::vector<Value>& resultvec); 58 static bool CheckAutoFillParameter( 59 const std::string& args, double size, std::vector<double>& out, std::vector<Value>& resultvec); 60 61 WeakPtr<RenderNode> renderNode_; 62 ACE_DISALLOW_COPY_AND_MOVE(TemplatesParser); 63 }; 64 } // namespace OHOS::Ace 65 66 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COMMON_LAYOUT_TEMPLATES_PARSER_H 67