30 struct RLengthElement {
35 struct RLengthParseElements {
41 bool Done()
const {
return fIndex == 3; }
46 if (tok.front() ==
'-' || tok.front() ==
'+')
47 fSignOrOp = tok.front();
50 return SetNumberAndGetError(tok.substr(1));
60 if (tok.front() ==
'-') {
66 }
else if (tok.front() ==
'+')
70 for (
const char &
c: tok) {
71 if (std::isdigit(
c) ||
c ==
'.') {
74 std::string err =
"syntax error: multiple '.' in ";
75 err += std::string(tok);
83 return SetUnitAndGetError(tok.substr(&
c - tok.data()));
92 fUnit = std::string(tok);
93 std::transform(fUnit.begin(), fUnit.end(), fUnit.begin(), [](
char c) { return std::tolower(c); });
100 case 0:
return SetMaybeSignOrOpAndGetError(tok);
101 case 1:
return SetNumberAndGetError(tok);
102 case 2:
return SetUnitAndGetError(tok);
103 default:
return "invalid syntax: too many / duplicate elements";
108 std::pair<RLengthElement, std::string> ToLengthElement()
const {
110 std::size_t posStrToD;
111 if (fNumber.empty()) {
112 return {{},
"empty floating point number"};
114 ret.fVal = std::stod(fNumber, &posStrToD);
115 if (posStrToD != fNumber.length())
116 return {{}, std::string(
"invalid floating point number ") + fNumber};
118 if (fSignOrOp ==
'-')
121 if (fUnit ==
"normal")
123 else if (fUnit ==
"px" || fUnit ==
"pixel")
125 else if (fUnit ==
"user")
128 return {{}, std::string(
"invalid unit, expect normal, px, or user but got ") + fUnit};
134 std::string err = parse.SetNextAndGetError(tok);
140 std::pair<RLengthElement, std::string> parseRes = parse.ToLengthElement();
141 if (!parseRes.second.empty())
142 return parseRes.second;
143 switch (parseRes.first.fKind) {
167 RLengthParseElements parse;
169 for (
const char c: val) {
172 std::string err = HandleToken(tok, parse, *
this);
175 <<
"' while parsing pad length for " <<
name <<
": " << err;
185 std::string err = HandleToken(tok, parse, *
this);
188 <<
"' while parsing pad length for " <<
name <<
": " << err;
192 if (parse.fIndex != 0) {
194 <<
"' while parsing pad length for " <<
name
195 <<
": missing elements, expect [+-] number (normal|px|user)";
209 std::stringstream strm;
#define R__ERROR_HERE(GROUP)
Pixel fPixel
The pixel coordinate summand.
User fUser
The user coordinate summand.
void SetFromAttrString(const std::string &val, const std::string &name)
Initialize a RPadLength from a style string.
Normal fNormal
The normalized coordinate summand.
basic_string_view< char > string_view
std::string ToAttributeString(const RColor &val)
Return a std::string representation of a RColor, suitable as input to ColorFromString().
RColor FromAttributeString(const std::string &str, const std::string &name, RColor *)
Initialize a RColor from a string value.
double fVal
Coordinate value.
A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the RPad.
A pixel coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the RPad.
A user coordinate, as defined by the EUserCoordSystem parameter of the RPad.