24#include "AstUtil/StringView.hpp"
25#include "AstUtil/ParseFormat.hpp"
26#include "AstUtil/Color.hpp"
27#include "AstUtil/GenericValue.hpp"
28#include "AstUtil/StringSplit.hpp"
29#include "AstUtil/StringUtil.hpp"
33class ByCommaAndRepeatedWhitespace;
50 : value_(value.value()) {}
58 errc_t toInt(
int& value)
const {
return aParseInt(value_, value); }
62 errc_t toDouble(
double& value)
const {
return aParseDouble(value_, value); }
70 errc_t toBool(
bool& value)
const {
return aParseBool(value_, value); }
77 std::string
toString()
const {
return std::string(value_); }
78 void toString(std::string& value)
const { value = std::string(value_); }
81 std::vector<ValueView> toVector()
const;
82 void toVector(std::vector<ValueView>& value)
const;
85 std::vector<double> toFortranDoubleVector()
const;
86 errc_t toFortranDoubleVector(std::vector<double>& value)
const;
89 std::vector<double> toDoubleVector()
const;
90 errc_t toDoubleVector(std::vector<double>& value)
const;
93 std::vector<int> toIntVector()
const;
94 errc_t toIntVector(std::vector<int>& value)
const;
102 operator StringView()
const {
return value_; }
104 const char* data()
const {
return value_.data(); }
105 size_t size()
const {
return value_.size(); }
107 using SplitterType = Splitter<ByCommaAndRepeatedWhitespace, SkipBracket>;
108 SplitterType split()
const;
110 template<
typename Delimiter>
111 inline strings_internal::Splitter<typename strings_internal::SelectDelimiter<Delimiter>::type, strings_internal::AllowEmpty, StringView>
112 split(Delimiter delimiter)
const {
113 using DelimiterType =
typename strings_internal::SelectDelimiter<Delimiter>::type;
114 return strings_internal::Splitter<DelimiterType, strings_internal::AllowEmpty, StringView>(
115 value_, DelimiterType(delimiter), strings_internal::AllowEmpty());
122inline std::vector<ValueView> ValueView::toVector()
const
124 std::vector<ValueView> value;
125 this->toVector(value);
134 while (pos < text.size()) {
137 if (std::isspace(
static_cast<unsigned char>(c))) {
138 size_t whitespace_start = pos;
140 while (pos < text.size() && std::isspace(
static_cast<unsigned char>(text[pos]))) {
144 if (pos < text.size() && text[pos] ==
',') {
147 while (pos < text.size() && std::isspace(
static_cast<unsigned char>(text[pos]))) {
151 return text.substr(whitespace_start, pos - whitespace_start);
156 size_t comma_start = pos;
159 while (pos < text.size() && std::isspace(
static_cast<unsigned char>(text[pos]))) {
163 return text.substr(comma_start, pos - comma_start);
170 return StringView(text.data() + text.size(), 0);
179 if (text.size() == 1) {
180 if (text[0] ==
'(' || text[0] ==
')') {
188inline void ValueView::toVector(std::vector<ValueView>& value)
const
190 value = split().operator std::vector<ValueView>();
193inline std::vector<double> ValueView::toFortranDoubleVector()
const
195 std::vector<double> value;
196 this->toFortranDoubleVector(value);
200inline errc_t ValueView::toFortranDoubleVector(std::vector<double> &value)
const
202 for (
auto& v : split()) {
204 if (errc_t rc =
ValueView(v).toFortranDouble(d)) {
212inline std::vector<double> ValueView::toDoubleVector()
const
214 std::vector<double> value;
215 this->toDoubleVector(value);
219inline errc_t ValueView::toDoubleVector(std::vector<double> &value)
const
221 for (
auto& v : split()) {
223 if (errc_t rc =
ValueView(v).toDouble(d)) {
231inline std::vector<int> ValueView::toIntVector()
const
233 std::vector<int> value;
234 this->toIntVector(value);
238inline errc_t ValueView::toIntVector(std::vector<int>& value)
const
240 for (
auto& v : split()) {
250inline ValueView::SplitterType ValueView::split()
const
逗号和重复空格分隔符
定义 ValueView.hpp:131
通用值类
定义 GenericValue.hpp:34
double toDouble() const
转换为浮点数,不支持 Fortran 格式浮点数
定义 ValueView.hpp:61
GenericValue toValue() const
转换为通用值
定义 ValueView.hpp:100
std::string toString() const
转换为字符串
定义 ValueView.hpp:77
Color toColor() const
转换为颜色值
定义 ValueView.hpp:73
int toInt() const
转换为整数
定义 ValueView.hpp:57
const StringView & toStringView() const
转换为字符串视图
定义 ValueView.hpp:97
const StringView & value() const
获取值视图
定义 ValueView.hpp:53
double toFortranDouble() const
转换为浮点数,支持 Fortran 格式浮点数,例如 "1.23D2","-1.23d3"
定义 ValueView.hpp:65
bool toBool() const
转换为布尔值
定义 ValueView.hpp:69
StringView aStripAsciiWhitespace(StringView str) noexcept
移除字符串首尾的ASCII空白字符
定义 StringUtil.hpp:82
strings_internal::Splitter< typename strings_internal::SelectDelimiter< Delimiter >::type, strings_internal::AllowEmpty, StringView > aStrSplit(StringView text, Delimiter delimiter)
字符串分割函数
定义 StringSplit.hpp:42