PropertyParserRatio.cpp 809 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "PropertyParserRatio.h"
  2. namespace Rml {
  3. PropertyParserRatio::PropertyParserRatio() {}
  4. PropertyParserRatio::~PropertyParserRatio() {}
  5. bool PropertyParserRatio::ParseValue(Property& property, const String& value, const ParameterMap& /*parameters*/) const
  6. {
  7. StringList parts;
  8. StringUtilities::ExpandString(parts, value, '/');
  9. if (parts.size() != 2)
  10. {
  11. return false;
  12. }
  13. float first_value = 0;
  14. if (!TypeConverter<String, float>::Convert(parts[0], first_value))
  15. {
  16. // Number conversion failed
  17. return false;
  18. }
  19. float second_value = 0;
  20. if (!TypeConverter<String, float>::Convert(parts[1], second_value))
  21. {
  22. // Number conversion failed
  23. return false;
  24. }
  25. property.value = Variant(Vector2f(first_value, second_value));
  26. property.unit = Unit::RATIO;
  27. return true;
  28. }
  29. } // namespace Rml