aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper/MeasureLengthMapper.cpp
blob: 9f5c2a2627d72d8f57680732a9ae1e2c8b52020e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "cru/ui/mapper/MeasureLengthMapper.h"
#include "cru/base/StringUtil.h"
#include "cru/ui/render/MeasureRequirement.h"

namespace cru::ui::mapper {
bool MeasureLengthMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
  return cru::string::CaseInsensitiveCompare(node->GetTag(), "MeasureLength") ==
         0;
}

render::MeasureLength MeasureLengthMapper::DoMapFromString(std::string str) {
  if (cru::string::CaseInsensitiveCompare(str, "notspecified") == 0) {
    return render::MeasureLength::NotSpecified();
  }
  if (cru::string::CaseInsensitiveCompare(str, "unspecified") == 0) {
    return render::MeasureLength::NotSpecified();
  }
  auto value = String::FromUtf8(str).ParseToFloat();
  if (value < 0) {
    return render::MeasureLength::NotSpecified();
  }
  return render::MeasureLength(value);
}

render::MeasureLength MeasureLengthMapper::DoMapFromXml(
    xml::XmlElementNode* node) {
  auto value_attr = node->GetOptionalAttributeValueCaseInsensitive("value");
  if (!value_attr) return {};
  return DoMapFromString(*value_attr);
}
}  // namespace cru::ui::mapper