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"
30#include "AstUtil/Math.hpp"
34class ByCommaAndRepeatedWhitespace;
54 : value_(value.value()) {}
64 errc_t toInt(
int& value)
const {
return aParseInt(value_, value); }
68 errc_t toDouble(
double& value)
const {
return aParseDouble(value_, value); }
73 errc_t toAngleRad(angle_d& value)
const {errc_t rc=
aParseDouble(value_, value); value=
deg2rad(value);
return rc;}
81 errc_t toBool(
bool& value)
const {
return aParseBool(value_, value); }
88 std::string
toString()
const {
return std::string(value_); }
89 void toString(std::string& value)
const { value = std::string(value_); }
92 std::vector<ValueView> toVector()
const;
93 void toVector(std::vector<ValueView>& value)
const;
96 std::vector<double> toFortranDoubleVector()
const;
97 errc_t toFortranDoubleVector(std::vector<double>& value)
const;
100 std::vector<double> toDoubleVector()
const;
101 errc_t toDoubleVector(std::vector<double>& value)
const;
104 std::vector<int> toIntVector()
const;
105 errc_t toIntVector(std::vector<int>& value)
const;
113 operator StringView()
const {
return value_; }
115 const char* data()
const {
return value_.data(); }
116 size_t size()
const {
return value_.size(); }
118 using SplitterType = Splitter<ByCommaAndRepeatedWhitespace, SkipBracket>;
119 SplitterType split()
const;
121 template<
typename Delimiter>
122 inline strings_internal::Splitter<typename strings_internal::SelectDelimiter<Delimiter>::type, strings_internal::AllowEmpty, StringView>
123 split(Delimiter delimiter)
const {
124 using DelimiterType =
typename strings_internal::SelectDelimiter<Delimiter>::type;
125 return strings_internal::Splitter<DelimiterType, strings_internal::AllowEmpty, StringView>(
126 value_, DelimiterType(delimiter), strings_internal::AllowEmpty());
133inline std::vector<ValueView> ValueView::toVector()
const
135 std::vector<ValueView> value;
136 this->toVector(value);
145 while (pos < text.size()) {
148 if (std::isspace(
static_cast<unsigned char>(c))) {
149 size_t whitespace_start = pos;
151 while (pos < text.size() && std::isspace(
static_cast<unsigned char>(text[pos]))) {
155 if (pos < text.size() && text[pos] ==
',') {
158 while (pos < text.size() && std::isspace(
static_cast<unsigned char>(text[pos]))) {
162 return text.substr(whitespace_start, pos - whitespace_start);
167 size_t comma_start = pos;
170 while (pos < text.size() && std::isspace(
static_cast<unsigned char>(text[pos]))) {
174 return text.substr(comma_start, pos - comma_start);
181 return StringView(text.data() + text.size(), 0);
190 if (text.size() == 1) {
191 if (text[0] ==
'(' || text[0] ==
')') {
199inline void ValueView::toVector(std::vector<ValueView>& value)
const
201 value = split().operator std::vector<ValueView>();
204inline std::vector<double> ValueView::toFortranDoubleVector()
const
206 std::vector<double> value;
207 this->toFortranDoubleVector(value);
211inline errc_t ValueView::toFortranDoubleVector(std::vector<double> &value)
const
213 for (
auto& v : split()) {
215 if (errc_t rc =
ValueView(v).toFortranDouble(d)) {
223inline std::vector<double> ValueView::toDoubleVector()
const
225 std::vector<double> value;
226 this->toDoubleVector(value);
230inline errc_t ValueView::toDoubleVector(std::vector<double> &value)
const
232 for (
auto& v : split()) {
234 if (errc_t rc =
ValueView(v).toDouble(d)) {
242inline std::vector<int> ValueView::toIntVector()
const
244 std::vector<int> value;
245 this->toIntVector(value);
249inline errc_t ValueView::toIntVector(std::vector<int>& value)
const
251 for (
auto& v : split()) {
261inline ValueView::SplitterType ValueView::split()
const
逗号和重复空格分隔符
定义 ValueView.hpp:142
通用值类
定义 GenericValue.hpp:34
double toDouble() const
转换为浮点数,不支持 Fortran 格式浮点数
定义 ValueView.hpp:67
GenericValue toValue() const
转换为通用值
定义 ValueView.hpp:111
std::string toString() const
转换为字符串
定义 ValueView.hpp:88
Color toColor() const
转换为颜色值
定义 ValueView.hpp:84
int toInt() const
转换为整数
定义 ValueView.hpp:63
const StringView & toStringView() const
转换为字符串视图
定义 ValueView.hpp:108
angle_d toAngleRad() const
转换为弧度
定义 ValueView.hpp:72
const StringView & value() const
获取值视图
定义 ValueView.hpp:59
double toFortranDouble() const
转换为浮点数,支持 Fortran 格式浮点数,例如 "1.23D2","-1.23d3"
定义 ValueView.hpp:76
bool toBool() const
转换为布尔值
定义 ValueView.hpp:80
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
A_ALWAYS_INLINE double deg2rad(double x)
将角度转换为弧度
定义 MathDegree.hpp:45