aboutsummaryrefslogtreecommitdiff
path: root/src/ui/mapper/MeasureLengthMapper.cpp
blob: 6a0f95e3c9076df689d788395382b1311a78f282 (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
#include "cru/ui/mapper/MeasureLengthMapper.h"
#include "cru/ui/render/MeasureRequirement.h"

namespace cru::ui::mapper {
bool MeasureLengthMapper::XmlElementIsOfThisType(xml::XmlElementNode* node) {
  return node->GetTag().CaseInsensitiveEqual(u"MeasureLength");
}

render::MeasureLength MeasureLengthMapper::DoMapFromString(String str) {
  if (str.CaseInsensitiveEqual(u"notspecified")) {
    return render::MeasureLength::NotSpecified();
  }
  if (str.CaseInsensitiveEqual(u"unspecified")) {
    return render::MeasureLength::NotSpecified();
  }
  auto value = str.ParseToFloat();
  if (value < 0) {
    return render::MeasureLength::NotSpecified();
  }
  return render::MeasureLength(value);
}

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