slot 0.0.1
A real time UI render framework
载入中...
搜索中...
未找到
PropertyParser.h
浏览该文件的文档.
1#pragma once
2
3#include <charconv>
4#include <cmath>
5#include <string_view>
6#include <system_error>
7
8namespace z8::ui {
9
16inline bool ParseBoolean(std::string_view text, bool &value) {
17 if (text == "true" || text == "True" || text == "1") {
18 value = true;
19 return true;
20 }
21 if (text == "false" || text == "False" || text == "0") {
22 value = false;
23 return true;
24 }
25 return false;
26}
27
34inline bool ParseFiniteFloat(std::string_view text, float &value) {
35 if (text.empty())
36 return false;
37 float parsed = 0.0f;
38 const auto result =
39 std::from_chars(text.data(), text.data() + text.size(), parsed);
40 if (result.ec != std::errc{} || result.ptr != text.data() + text.size() ||
41 !std::isfinite(parsed))
42 return false;
43 // 输出只在完整解析后提交,调用方即使直接传入成员也不会遭遇半更新。
44 value = parsed;
45 return true;
46}
47
48} // namespace z8::ui
资源的强类型引用,同时覆盖持久化 ID 与运行时索引两种边界。
Definition ResourceRef.h:36
Definition Application.h:18
bool ParseBoolean(std::string_view text, bool &value)
Definition PropertyParser.h:16
bool ParseFiniteFloat(std::string_view text, float &value)
Definition PropertyParser.h:34