| 156 | }; |
| 157 | |
| 158 | static std::vector<std::pair<CSSValue, float>> parseCommaSeparatedValues(std::string_view values, bool allowPercent = false, bool allowAuto = false) { |
| 159 | std::vector<std::pair<CSSValue, float>> result; |
| 160 | auto parts = values | std::ranges::views::split(','); |
| 161 | for (auto&& part : parts) { |
| 162 | auto partStr = Slice{&*part.begin(), static_cast<size_t>(std::ranges::distance(part))}.trimSpace(); |
| 163 | if (allowAuto && partStr == "auto") { |
| 164 | result.push_back({CSSValue::Auto, 0}); |
| 165 | } else if (allowPercent && !partStr.empty() && partStr.back() == '%') { |
| 166 | std::string str(partStr); |
| 167 | if (auto num = safeStringToFloat(str)) { |
| 168 | result.push_back({CSSValue::Percentage, num.value()}); |
| 169 | } else { |
| 170 | return {}; |
| 171 | } |
| 172 | } else { |
| 173 | std::string str(partStr); |
| 174 | if (auto num = safeStringToFloat(str)) { |
| 175 | result.push_back({CSSValue::Number, num.value()}); |
| 176 | } else { |
| 177 | return {}; |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | return result; |
| 182 | } |
| 183 | |
| 184 | static void setEdges(YGNodeRef node, const std::vector<std::pair<CSSValue, float>>& values, void (*setter)(YGNodeRef, YGEdge, float), void (*percentSetter)(YGNodeRef, YGEdge, float) = nullptr, void (*autoSetter)(YGNodeRef, YGEdge) = nullptr) { |
| 185 | auto setValue = [&](YGEdge edge, const std::pair<CSSValue, float>& value) { |