diff --git a/ReactCommon/fabric/attributedstring/AttributedString.h b/ReactCommon/fabric/attributedstring/AttributedString.h index 7a952e4bfcf..8b74d9abca0 100644 --- a/ReactCommon/fabric/attributedstring/AttributedString.h +++ b/ReactCommon/fabric/attributedstring/AttributedString.h @@ -51,6 +51,12 @@ class AttributedString : public Sealable, public DebugStringConvertible { bool operator!=(const Fragment &rhs) const; }; + class Range { + public: + int location{0}; + int length{0}; + }; + using Fragments = better::small_vector; /* diff --git a/ReactCommon/fabric/attributedstring/conversions.h b/ReactCommon/fabric/attributedstring/conversions.h index 05528837edb..a5d3b73a07b 100644 --- a/ReactCommon/fabric/attributedstring/conversions.h +++ b/ReactCommon/fabric/attributedstring/conversions.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -444,6 +445,26 @@ inline ParagraphAttributes convertRawProp( return paragraphAttributes; } +inline void fromRawValue( + RawValue const &value, + AttributedString::Range &result) { + auto map = (better::map)value; + + auto start = map.find("start"); + if (start != map.end()) { + result.location = start->second; + } + auto end = map.find("end"); + if (end != map.end()) { + result.length = start->second - result.location; + } +} + +inline std::string toString(AttributedString::Range const &range) { + return "{location: " + folly::to(range.location) + + ", length: " + folly::to(range.length) + "}"; +} + #ifdef ANDROID inline folly::dynamic toDynamic( @@ -562,6 +583,13 @@ inline folly::dynamic toDynamic(const AttributedString &attributedString) { return value; } +inline folly::dynamic toDynamic(AttributedString::Range const &range) { + folly::dynamic dynamicValue = folly::dynamic::object(); + dynamicValue["location"] = range.location; + dynamicValue["length"] = range.length; + return dynamicValue; +} + #endif } // namespace react