messageformat2_data_model.h 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600
  1. // © 2024 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. #include "unicode/utypes.h"
  4. #ifndef MESSAGEFORMAT_DATA_MODEL_H
  5. #define MESSAGEFORMAT_DATA_MODEL_H
  6. #if U_SHOW_CPLUSPLUS_API
  7. #if !UCONFIG_NO_FORMATTING
  8. #if !UCONFIG_NO_MF2
  9. #include "unicode/localpointer.h"
  10. #include "unicode/messageformat2_data_model_names.h"
  11. #ifndef U_HIDE_DEPRECATED_API
  12. #include <algorithm>
  13. #include <cstddef>
  14. #include <iterator>
  15. #include <optional>
  16. #include <variant>
  17. #include <vector>
  18. U_NAMESPACE_BEGIN
  19. class UVector;
  20. // Helpers
  21. // Note: this _must_ be declared `inline` or else gcc will generate code
  22. // for its instantiations, which needs to be avoided because it returns
  23. // a std::vector
  24. template<typename T>
  25. static inline std::vector<T> toStdVector(const T* arr, int32_t len) {
  26. std::vector<T> result;
  27. for (int32_t i = 0; i < len; i++) {
  28. result.push_back(arr[i]);
  29. }
  30. return result;
  31. }
  32. #if defined(U_REAL_MSVC)
  33. #pragma warning(push)
  34. // Ignore warning 4251 as these templates are instantiated later in this file,
  35. // after the classes used to instantiate them have been defined.
  36. #pragma warning(disable: 4251)
  37. #endif
  38. namespace message2 {
  39. class Checker;
  40. class MFDataModel;
  41. class MessageFormatter;
  42. class Parser;
  43. class Serializer;
  44. namespace data_model {
  45. class Binding;
  46. class Literal;
  47. class Operator;
  48. /**
  49. * The `Literal` class corresponds to the `literal` nonterminal in the MessageFormat 2 grammar,
  50. * https://github.com/unicode-org/message-format-wg/blob/main/spec/message.abnf and the
  51. * `Literal` interface defined in
  52. * // https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#expressions
  53. *
  54. * `Literal` is immutable, copyable and movable.
  55. *
  56. * @internal ICU 75 technology preview
  57. * @deprecated This API is for technology preview only.
  58. */
  59. class U_I18N_API Literal : public UObject {
  60. public:
  61. /**
  62. * Returns the quoted representation of this literal (enclosed in '|' characters)
  63. *
  64. * @return A string representation of the literal enclosed in quote characters.
  65. *
  66. * @internal ICU 75 technology preview
  67. * @deprecated This API is for technology preview only.
  68. */
  69. UnicodeString quoted() const;
  70. /**
  71. * Returns the parsed string contents of this literal.
  72. *
  73. * @return A string representation of this literal.
  74. *
  75. * @internal ICU 75 technology preview
  76. * @deprecated This API is for technology preview only.
  77. */
  78. const UnicodeString& unquoted() const;
  79. /**
  80. * Determines if this literal appeared as a quoted literal in the message.
  81. *
  82. * @return true if and only if this literal appeared as a quoted literal in the
  83. * message.
  84. *
  85. * @internal ICU 75 technology preview
  86. * @deprecated This API is for technology preview only.
  87. */
  88. UBool isQuoted() const { return thisIsQuoted; }
  89. /**
  90. * Literal constructor.
  91. *
  92. * @param q True if and only if this literal was parsed with the `quoted` nonterminal
  93. * (appeared enclosed in '|' characters in the message text).
  94. * @param s The string contents of this literal; escape sequences are assumed to have
  95. * been interpreted already.
  96. *
  97. * @internal ICU 75 technology preview
  98. * @deprecated This API is for technology preview only.
  99. */
  100. Literal(UBool q, const UnicodeString& s) : thisIsQuoted(q), contents(s) {}
  101. /**
  102. * Copy constructor.
  103. *
  104. * @internal ICU 75 technology preview
  105. * @deprecated This API is for technology preview only.
  106. */
  107. Literal(const Literal& other) : thisIsQuoted(other.thisIsQuoted), contents(other.contents) {}
  108. /**
  109. * Non-member swap function.
  110. * @param l1 will get l2's contents
  111. * @param l2 will get l1's contents
  112. *
  113. * @internal ICU 75 technology preview
  114. * @deprecated This API is for technology preview only.
  115. */
  116. friend inline void swap(Literal& l1, Literal& l2) noexcept {
  117. using std::swap;
  118. swap(l1.thisIsQuoted, l2.thisIsQuoted);
  119. swap(l1.contents, l2.contents);
  120. }
  121. /**
  122. * Assignment operator.
  123. *
  124. * @internal ICU 75 technology preview
  125. * @deprecated This API is for technology preview only.
  126. */
  127. Literal& operator=(Literal) noexcept;
  128. /**
  129. * Default constructor.
  130. * Puts the Literal into a valid but undefined state.
  131. *
  132. * @internal ICU 75 technology preview
  133. * @deprecated This API is for technology preview only.
  134. */
  135. Literal() = default;
  136. /**
  137. * Less than operator. Compares `this.stringContents()` with
  138. * `other.stringContents()`. This method is used in representing
  139. * the mapping from key lists to patterns in a message with variants,
  140. * and is not expected to be useful otherwise.
  141. *
  142. * @param other The Literal to compare to this one.
  143. * @return true if the parsed string corresponding to this `Literal`
  144. * is less than the parsed string corresponding to the other `Literal`
  145. * (according to `UnicodeString`'s less-than operator).
  146. * Returns false otherwise.
  147. *
  148. * @internal ICU 75 technology preview
  149. * @deprecated This API is for technology preview only.
  150. */
  151. bool operator<(const Literal& other) const;
  152. /**
  153. * Equality operator. Compares `this.stringContents()` with
  154. * `other.stringContents()`. This method is used in representing
  155. * the mapping from key lists to patterns in a message with variants,
  156. * and is not expected to be useful otherwise.
  157. *
  158. * @param other The Literal to compare to this one.
  159. * @return true if the parsed string corresponding to this `Literal`
  160. * equals the parsed string corresponding to the other `Literal`
  161. * (according to `UnicodeString`'s equality operator).
  162. * Returns false otherwise.
  163. *
  164. * @internal ICU 75 technology preview
  165. * @deprecated This API is for technology preview only.
  166. */
  167. bool operator==(const Literal& other) const;
  168. /**
  169. * Destructor.
  170. *
  171. * @internal ICU 75 technology preview
  172. * @deprecated This API is for technology preview only.
  173. */
  174. virtual ~Literal();
  175. private:
  176. /* const */ bool thisIsQuoted = false;
  177. /* const */ UnicodeString contents;
  178. };
  179. } // namespace data_model
  180. } // namespace message2
  181. /// @cond DOXYGEN_IGNORE
  182. // Export an explicit template instantiation of the LocalPointer that is used as a
  183. // data member of various MFDataModel classes.
  184. // (When building DLLs for Windows this is required.)
  185. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  186. // for similar examples.)
  187. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  188. template class U_I18N_API LocalPointerBase<message2::data_model::Literal>;
  189. template class U_I18N_API LocalArray<message2::data_model::Literal>;
  190. #endif
  191. #if defined(U_REAL_MSVC)
  192. #pragma warning(pop)
  193. #endif
  194. /// @endcond
  195. U_NAMESPACE_END
  196. /// @cond DOXYGEN_IGNORE
  197. // Export an explicit template instantiation of the std::variants and std::optionals
  198. // that are used as a data member of various MFDataModel classes.
  199. // (When building DLLs for Windows this is required.)
  200. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  201. // for similar examples.)
  202. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  203. #if defined(U_REAL_MSVC) && defined(_MSVC_STL_VERSION)
  204. struct U_I18N_API std::_Nontrivial_dummy_type;
  205. template class U_I18N_API std::_Variant_storage_<false, icu::UnicodeString, icu::message2::data_model::Literal>;
  206. #endif
  207. template class U_I18N_API std::variant<icu::UnicodeString, icu::message2::data_model::Literal>;
  208. template class U_I18N_API std::optional<std::variant<icu::UnicodeString, icu::message2::data_model::Literal>>;
  209. template class U_I18N_API std::optional<icu::message2::data_model::Literal>;
  210. #endif
  211. /// @endcond
  212. U_NAMESPACE_BEGIN
  213. namespace message2 {
  214. namespace data_model {
  215. /**
  216. * The `Operand` class corresponds to the `operand` nonterminal in the MessageFormat 2 grammar,
  217. * https://github.com/unicode-org/message-format-wg/blob/main/spec/message.abnf .
  218. * It represents a `Literal | VariableRef` -- see the `operand?` field of the `FunctionRef`
  219. * interface defined at:
  220. * https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#expressions
  221. * with the difference that it can also represent a null operand (the absent operand in an
  222. * `annotation` with no operand).
  223. *
  224. * `Operand` is immutable and is copyable and movable.
  225. *
  226. * @internal ICU 75 technology preview
  227. * @deprecated This API is for technology preview only.
  228. */
  229. class U_I18N_API Operand : public UObject {
  230. public:
  231. /**
  232. * Determines if this operand represents a variable.
  233. *
  234. * @return True if and only if the operand is a variable.
  235. *
  236. * @internal ICU 75 technology preview
  237. * @deprecated This API is for technology preview only.
  238. */
  239. UBool isVariable() const;
  240. /**
  241. * Determines if this operand represents a literal.
  242. *
  243. * @return True if and only if the operand is a literal.
  244. *
  245. * @internal ICU 75 technology preview
  246. * @deprecated This API is for technology preview only.
  247. */
  248. UBool isLiteral() const;
  249. /**
  250. * Determines if this operand is the null operand.
  251. *
  252. * @return True if and only if the operand is the null operand.
  253. *
  254. * @internal ICU 75 technology preview
  255. * @deprecated This API is for technology preview only.
  256. */
  257. virtual UBool isNull() const;
  258. /**
  259. * Returns a reference to this operand's variable name.
  260. * Precondition: isVariable()
  261. *
  262. * @return A reference to the name of the variable
  263. *
  264. * @internal ICU 75 technology preview
  265. * @deprecated This API is for technology preview only.
  266. */
  267. const UnicodeString& asVariable() const;
  268. /**
  269. * Returns a reference to this operand's literal contents.
  270. * Precondition: isLiteral()
  271. *
  272. * @return A reference to the literal
  273. *
  274. * @internal ICU 75 technology preview
  275. * @deprecated This API is for technology preview only.
  276. */
  277. const Literal& asLiteral() const;
  278. /**
  279. * Default constructor.
  280. * Creates a null Operand.
  281. *
  282. * @internal ICU 75 technology preview
  283. * @deprecated This API is for technology preview only.
  284. */
  285. Operand() : contents(std::nullopt) {}
  286. /**
  287. * Variable operand constructor.
  288. *
  289. * @param v The variable name; an operand corresponding
  290. * to a reference to `v` is returned.
  291. *
  292. * @internal ICU 75 technology preview
  293. * @deprecated This API is for technology preview only.
  294. */
  295. explicit Operand(const UnicodeString& v) : contents(VariableName(v)) {}
  296. /**
  297. * Literal operand constructor.
  298. *
  299. * @param l The literal to use for this operand; an operand
  300. * corresponding to `l` is returned.
  301. *
  302. * @internal ICU 75 technology preview
  303. * @deprecated This API is for technology preview only.
  304. */
  305. explicit Operand(const Literal& l) : contents(l) {}
  306. /**
  307. * Non-member swap function.
  308. * @param o1 will get o2's contents
  309. * @param o2 will get o1's contents
  310. *
  311. * @internal ICU 75 technology preview
  312. * @deprecated This API is for technology preview only.
  313. */
  314. friend inline void swap(Operand& o1, Operand& o2) noexcept {
  315. using std::swap;
  316. (void) o1;
  317. (void) o2;
  318. swap(o1.contents, o2.contents);
  319. }
  320. /**
  321. * Assignment operator.
  322. *
  323. * @internal ICU 75 technology preview
  324. * @deprecated This API is for technology preview only.
  325. */
  326. virtual Operand& operator=(Operand) noexcept;
  327. /**
  328. * Copy constructor.
  329. *
  330. * @internal ICU 75 technology preview
  331. * @deprecated This API is for technology preview only.
  332. */
  333. Operand(const Operand&);
  334. /**
  335. * Destructor.
  336. *
  337. * @internal ICU 75 technology preview
  338. * @deprecated This API is for technology preview only.
  339. */
  340. virtual ~Operand();
  341. private:
  342. std::optional<std::variant<VariableName, Literal>> contents;
  343. }; // class Operand
  344. /**
  345. * The `Key` class corresponds to the `key` nonterminal in the MessageFormat 2 grammar,
  346. * https://github.com/unicode-org/message-format-wg/blob/main/spec/message.abnf .
  347. * It also corresponds to
  348. * the `Literal | CatchallKey` that is the
  349. * element type of the `keys` array in the `Variant` interface
  350. * defined in https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#messages
  351. *
  352. * A key is either a literal or the wildcard symbol (represented in messages as '*')
  353. *
  354. * `Key` is immutable, copyable and movable.
  355. *
  356. * @internal ICU 75 technology preview
  357. * @deprecated This API is for technology preview only.
  358. */
  359. class U_I18N_API Key : public UObject {
  360. public:
  361. /**
  362. * Determines if this is a wildcard key
  363. *
  364. * @return True if and only if this is the wildcard key
  365. *
  366. * @internal ICU 75 technology preview
  367. * @deprecated This API is for technology preview only.
  368. */
  369. UBool isWildcard() const { return !contents.has_value(); }
  370. /**
  371. * Returns the contents of this key as a literal.
  372. * Precondition: !isWildcard()
  373. *
  374. * @return The literal contents of the key
  375. *
  376. * @internal ICU 75 technology preview
  377. * @deprecated This API is for technology preview only.
  378. */
  379. const Literal& asLiteral() const;
  380. /**
  381. * Copy constructor.
  382. *
  383. * @internal ICU 75 technology preview
  384. * @deprecated This API is for technology preview only.
  385. */
  386. Key(const Key& other) : contents(other.contents) {}
  387. /**
  388. * Wildcard constructor; constructs a Key representing the
  389. * catchall or wildcard key, '*'.
  390. *
  391. * @internal ICU 75 technology preview
  392. * @deprecated This API is for technology preview only.
  393. */
  394. Key() : contents(std::nullopt) {}
  395. /**
  396. * Literal key constructor.
  397. *
  398. * @param lit A Literal to use for this key. The result matches the
  399. * literal `lit`.
  400. *
  401. * @internal ICU 75 technology preview
  402. * @deprecated This API is for technology preview only.
  403. */
  404. explicit Key(const Literal& lit) : contents(lit) {}
  405. /**
  406. * Non-member swap function.
  407. * @param k1 will get k2's contents
  408. * @param k2 will get k1's contents
  409. *
  410. * @internal ICU 75 technology preview
  411. * @deprecated This API is for technology preview only.
  412. */
  413. friend inline void swap(Key& k1, Key& k2) noexcept {
  414. using std::swap;
  415. swap(k1.contents, k2.contents);
  416. }
  417. /**
  418. * Assignment operator
  419. *
  420. * @internal ICU 75 technology preview
  421. * @deprecated This API is for technology preview only.
  422. */
  423. Key& operator=(Key) noexcept;
  424. /**
  425. * Less than operator. Compares the literal of `this` with the literal of `other`.
  426. * This method is used in representing the mapping from key lists to patterns
  427. * in a message with variants, and is not expected to be useful otherwise.
  428. *
  429. * @param other The Key to compare to this one.
  430. * @return true if the two `Key`s are not wildcards and if `this.asLiteral()`
  431. * < `other.asLiteral()`.
  432. * Returns false otherwise.
  433. *
  434. * @internal ICU 75 technology preview
  435. * @deprecated This API is for technology preview only.
  436. */
  437. bool operator<(const Key& other) const;
  438. /**
  439. * Equality operator. Compares the literal of `this` with the literal of `other`.
  440. * This method is used in representing the mapping from key lists to patterns
  441. * in a message with variants, and is not expected to be useful otherwise.
  442. *
  443. * @param other The Key to compare to this one.
  444. * @return true if either both `Key`s are wildcards, or `this.asLiteral()`
  445. * == `other.asLiteral()`.
  446. * Returns false otherwise.
  447. *
  448. * @internal ICU 75 technology preview
  449. * @deprecated This API is for technology preview only.
  450. */
  451. bool operator==(const Key& other) const;
  452. /**
  453. * Destructor.
  454. *
  455. * @internal ICU 75 technology preview
  456. * @deprecated This API is for technology preview only.
  457. */
  458. virtual ~Key();
  459. private:
  460. /* const */ std::optional<Literal> contents;
  461. }; // class Key
  462. } // namespace data_model
  463. } // namespace message2
  464. /// @cond DOXYGEN_IGNORE
  465. // Export an explicit template instantiation of the LocalPointer that is used as a
  466. // data member of various MFDataModel classes.
  467. // (When building DLLs for Windows this is required.)
  468. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  469. // for similar examples.)
  470. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  471. template class U_I18N_API LocalPointerBase<message2::data_model::Key>;
  472. template class U_I18N_API LocalArray<message2::data_model::Key>;
  473. #endif
  474. /// @endcond
  475. namespace message2 {
  476. namespace data_model {
  477. /**
  478. * The `SelectorKeys` class represents the key list for a single variant.
  479. * It corresponds to the `keys` array in the `Variant` interface
  480. * defined in https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#messages
  481. *
  482. * `SelectorKeys` is immutable, copyable and movable.
  483. *
  484. * @internal ICU 75 technology preview
  485. * @deprecated This API is for technology preview only.
  486. */
  487. class U_I18N_API SelectorKeys : public UObject {
  488. public:
  489. /**
  490. * Returns the underlying list of keys.
  491. *
  492. * @return The list of keys for this variant.
  493. * Returns an empty list if allocating this `SelectorKeys`
  494. * object previously failed.
  495. *
  496. * @internal ICU 75 technology preview
  497. * @deprecated This API is for technology preview only.
  498. */
  499. std::vector<Key> getKeys() const {
  500. return toStdVector<Key>(keys.getAlias(), len);
  501. }
  502. /**
  503. * The mutable `SelectorKeys::Builder` class allows the key list to be constructed
  504. * one key at a time.
  505. *
  506. * Builder is not copyable or movable.
  507. *
  508. * @internal ICU 75 technology preview
  509. * @deprecated This API is for technology preview only.
  510. */
  511. class U_I18N_API Builder : public UMemory {
  512. private:
  513. friend class SelectorKeys;
  514. UVector* keys; // This is a raw pointer and not a LocalPointer<UVector> to avoid undefined behavior warnings,
  515. // since UVector is forward-declared
  516. // The vector owns its elements
  517. public:
  518. /**
  519. * Adds a single key to the list.
  520. *
  521. * @param key The key to be added. Passed by move
  522. * @param status Input/output error code
  523. * @return A reference to the builder.
  524. *
  525. * @internal ICU 75 technology preview
  526. * @deprecated This API is for technology preview only.
  527. */
  528. Builder& add(Key&& key, UErrorCode& status) noexcept;
  529. /**
  530. * Constructs a new immutable `SelectorKeys` using the list of keys
  531. * set with previous `add()` calls.
  532. *
  533. * The builder object (`this`) can still be used after calling `build()`.
  534. *
  535. * @param status Input/output error code
  536. * @return The new SelectorKeys object
  537. *
  538. * @internal ICU 75 technology preview
  539. * @deprecated This API is for technology preview only.
  540. */
  541. SelectorKeys build(UErrorCode& status) const;
  542. /**
  543. * Default constructor.
  544. * Returns a Builder with an empty list of keys.
  545. *
  546. * @param status Input/output error code
  547. *
  548. * @internal ICU 75 technology preview
  549. * @deprecated This API is for technology preview only.
  550. */
  551. Builder(UErrorCode& status);
  552. /**
  553. * Destructor.
  554. *
  555. * @internal ICU 75 technology preview
  556. * @deprecated This API is for technology preview only.
  557. */
  558. virtual ~Builder();
  559. Builder(const Builder&) = delete;
  560. Builder& operator=(const Builder&) = delete;
  561. Builder(Builder&&) = delete;
  562. Builder& operator=(Builder&&) = delete;
  563. }; // class SelectorKeys::Builder
  564. /**
  565. * Less than operator. Compares the two key lists lexicographically.
  566. * This method makes it possible for a `SelectorKeys` to be used as a map
  567. * key, which allows variants to be represented as a map. It is not expected
  568. * to be useful otherwise.
  569. *
  570. * @param other The SelectorKeys to compare to this one.
  571. * @return true if `this` is less than `other`, comparing the two key lists
  572. * lexicographically.
  573. * Returns false otherwise.
  574. *
  575. * @internal ICU 75 technology preview
  576. * @deprecated This API is for technology preview only.
  577. */
  578. bool operator<(const SelectorKeys& other) const;
  579. /**
  580. * Default constructor.
  581. * Puts the SelectorKeys into a valid but undefined state.
  582. *
  583. * @internal ICU 75 technology preview
  584. * @deprecated This API is for technology preview only.
  585. */
  586. SelectorKeys() : len(0) {}
  587. /**
  588. * Non-member swap function.
  589. * @param s1 will get s2's contents
  590. * @param s2 will get s1's contents
  591. *
  592. * @internal ICU 75 technology preview
  593. * @deprecated This API is for technology preview only.
  594. */
  595. friend inline void swap(SelectorKeys& s1, SelectorKeys& s2) noexcept {
  596. using std::swap;
  597. swap(s1.len, s2.len);
  598. swap(s1.keys, s2.keys);
  599. }
  600. /**
  601. * Copy constructor.
  602. *
  603. * @internal ICU 75 technology preview
  604. * @deprecated This API is for technology preview only.
  605. */
  606. SelectorKeys(const SelectorKeys& other);
  607. /**
  608. * Assignment operator.
  609. *
  610. * @internal ICU 75 technology preview
  611. * @deprecated This API is for technology preview only.
  612. */
  613. SelectorKeys& operator=(SelectorKeys other) noexcept;
  614. /**
  615. * Destructor.
  616. *
  617. * @internal ICU 75 technology preview
  618. * @deprecated This API is for technology preview only.
  619. */
  620. virtual ~SelectorKeys();
  621. private:
  622. friend class Builder;
  623. friend class message2::Checker;
  624. friend class message2::MessageFormatter;
  625. friend class message2::Serializer;
  626. /* const */ LocalArray<Key> keys;
  627. /* const */ int32_t len;
  628. const Key* getKeysInternal() const;
  629. SelectorKeys(const UVector& ks, UErrorCode& status);
  630. }; // class SelectorKeys
  631. } // namespace data_model
  632. namespace data_model {
  633. class Operator;
  634. /**
  635. * An `Option` pairs an option name with an Operand.
  636. *
  637. * `Option` is immutable, copyable and movable.
  638. *
  639. * @internal ICU 75 technology preview
  640. * @deprecated This API is for technology preview only.
  641. */
  642. class U_I18N_API Option : public UObject {
  643. public:
  644. /**
  645. * Accesses the right-hand side of the option.
  646. *
  647. * @return A reference to the operand.
  648. *
  649. * @internal ICU 75 technology preview
  650. * @deprecated This API is for technology preview only.
  651. */
  652. const Operand& getValue() const { return rand; }
  653. /**
  654. * Accesses the left-hand side of the option.
  655. *
  656. * @return A reference to the option name.
  657. *
  658. * @internal ICU 75 technology preview
  659. * @deprecated This API is for technology preview only.
  660. */
  661. const UnicodeString& getName() const { return name; }
  662. /**
  663. * Constructor. Returns an `Option` representing the
  664. * named option "name=rand".
  665. *
  666. * @param n The name of the option.
  667. * @param r The value of the option.
  668. *
  669. * @internal ICU 75 technology preview
  670. * @deprecated This API is for technology preview only.
  671. */
  672. Option(const UnicodeString& n, Operand&& r) : name(n), rand(std::move(r)) {}
  673. /**
  674. * Default constructor.
  675. * Returns an Option in a valid but undefined state.
  676. *
  677. * @internal ICU 75 technology preview
  678. * @deprecated This API is for technology preview only.
  679. */
  680. Option() {}
  681. /**
  682. * Non-member swap function.
  683. * @param o1 will get o2's contents
  684. * @param o2 will get o1's contents
  685. *
  686. * @internal ICU 75 technology preview
  687. * @deprecated This API is for technology preview only.
  688. */
  689. friend inline void swap(Option& o1, Option& o2) noexcept {
  690. using std::swap;
  691. swap(o1.name, o2.name);
  692. swap(o1.rand, o2.rand);
  693. }
  694. /**
  695. * Copy constructor.
  696. *
  697. * @internal ICU 75 technology preview
  698. * @deprecated This API is for technology preview only.
  699. */
  700. Option(const Option& other);
  701. /**
  702. * Assignment operator
  703. *
  704. * @internal ICU 75 technology preview
  705. * @deprecated This API is for technology preview only.
  706. */
  707. Option& operator=(Option other) noexcept;
  708. /**
  709. * Destructor.
  710. *
  711. * @internal ICU 75 technology preview
  712. * @deprecated This API is for technology preview only.
  713. */
  714. virtual ~Option();
  715. private:
  716. /* const */ UnicodeString name;
  717. /* const */ Operand rand;
  718. }; // class Option
  719. } // namespace data_model
  720. } // namespace message2
  721. /// @cond DOXYGEN_IGNORE
  722. // Export an explicit template instantiation of the LocalPointer that is used as a
  723. // data member of various MFDataModel classes.
  724. // (When building DLLs for Windows this is required.)
  725. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  726. // for similar examples.)
  727. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  728. template class U_I18N_API LocalPointerBase<message2::data_model::Option>;
  729. template class U_I18N_API LocalArray<message2::data_model::Option>;
  730. #endif
  731. /// @endcond
  732. namespace message2 {
  733. namespace data_model {
  734. // Internal only
  735. #ifndef U_IN_DOXYGEN
  736. // Options
  737. // This is a wrapper class around a vector of options that provides lookup operations
  738. class U_I18N_API OptionMap : public UObject {
  739. public:
  740. int32_t size() const;
  741. // Needs to take an error code b/c an earlier copy might have failed
  742. const Option& getOption(int32_t, UErrorCode&) const;
  743. friend inline void swap(OptionMap& m1, OptionMap& m2) noexcept {
  744. using std::swap;
  745. swap(m1.bogus, m2.bogus);
  746. swap(m1.options, m2.options);
  747. swap(m1.len, m2.len);
  748. }
  749. OptionMap() : len(0) {}
  750. OptionMap(const OptionMap&);
  751. OptionMap& operator=(OptionMap);
  752. std::vector<Option> getOptions() const {
  753. return toStdVector<Option>(options.getAlias(), len);
  754. }
  755. OptionMap(const UVector&, UErrorCode&);
  756. OptionMap(Option*, int32_t);
  757. virtual ~OptionMap();
  758. class U_I18N_API Builder : public UObject {
  759. private:
  760. UVector* options;
  761. bool checkDuplicates = true;
  762. public:
  763. Builder& add(Option&& opt, UErrorCode&);
  764. Builder(UErrorCode&);
  765. static Builder attributes(UErrorCode&);
  766. // As this class is private, build() is destructive
  767. OptionMap build(UErrorCode&);
  768. friend inline void swap(Builder& m1, Builder& m2) noexcept {
  769. using std::swap;
  770. swap(m1.options, m2.options);
  771. swap(m1.checkDuplicates, m2.checkDuplicates);
  772. }
  773. Builder(Builder&&);
  774. Builder(const Builder&) = delete;
  775. Builder& operator=(Builder) noexcept;
  776. virtual ~Builder();
  777. }; // class OptionMap::Builder
  778. private:
  779. friend class message2::Serializer;
  780. bool bogus = false;
  781. LocalArray<Option> options;
  782. int32_t len;
  783. }; // class OptionMap
  784. #endif
  785. } // namespace data_model
  786. } // namespace message2
  787. U_NAMESPACE_END
  788. U_NAMESPACE_BEGIN
  789. namespace message2 {
  790. namespace data_model {
  791. /**
  792. * The `Operator` class corresponds to the `FunctionRef` type in the
  793. * `Expression` interface defined in
  794. * https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#patterns
  795. *
  796. * It represents the annotation that an expression can have: a function name paired
  797. * with a map from option names to operands (possibly empty).
  798. *
  799. * `Operator` is immutable, copyable and movable.
  800. *
  801. * @internal ICU 75 technology preview
  802. * @deprecated This API is for technology preview only.
  803. */
  804. class U_I18N_API Operator : public UObject {
  805. public:
  806. /**
  807. * Accesses the function name.
  808. *
  809. * @return The function name of this operator.
  810. *
  811. * @internal ICU 75 technology preview
  812. * @deprecated This API is for technology preview only.
  813. */
  814. const FunctionName& getFunctionName() const;
  815. /**
  816. * Accesses function options.
  817. *
  818. * @return A vector of function options for this operator.
  819. *
  820. * @internal ICU 75 technology preview
  821. * @deprecated This API is for technology preview only.
  822. */
  823. std::vector<Option> getOptions() const {
  824. return options.getOptions();
  825. }
  826. /**
  827. * The mutable `Operator::Builder` class allows the operator to be constructed
  828. * incrementally.
  829. *
  830. * Builder is not copyable or movable.
  831. *
  832. * @internal ICU 75 technology preview
  833. * @deprecated This API is for technology preview only.
  834. */
  835. class U_I18N_API Builder : public UMemory {
  836. private:
  837. friend class Operator;
  838. FunctionName functionName;
  839. OptionMap::Builder options;
  840. public:
  841. /**
  842. * Sets this operator to be a function annotation and sets its name
  843. * to `func`.
  844. *
  845. * @param func The function name.
  846. * @return A reference to the builder.
  847. *
  848. * @internal ICU 75 technology preview
  849. * @deprecated This API is for technology preview only.
  850. */
  851. Builder& setFunctionName(FunctionName&& func);
  852. /**
  853. * Sets this operator to be a function annotation and adds a
  854. * single option.
  855. *
  856. * @param key The name of the option.
  857. * @param value The value (right-hand side) of the option.
  858. * @param status Input/output error code.
  859. * @return A reference to the builder.
  860. *
  861. * @internal ICU 75 technology preview
  862. * @deprecated This API is for technology preview only.
  863. */
  864. Builder& addOption(const UnicodeString &key, Operand&& value, UErrorCode& status) noexcept;
  865. /**
  866. * Constructs a new immutable `Operator` using the
  867. * function name and options that were previously set.
  868. *
  869. * The builder object (`this`) can still be used after calling `build()`.
  870. *
  871. * The `build()` method is non-const for internal implementation reasons,
  872. * but is observably const.
  873. *
  874. * @param status Input/output error code.
  875. * @return The new Operator
  876. *
  877. * @internal ICU 75 technology preview
  878. * @deprecated This API is for technology preview only.
  879. */
  880. Operator build(UErrorCode& status);
  881. /**
  882. * Default constructor.
  883. * Returns a Builder with no function name or options set.
  884. *
  885. * @param status Input/output error code.
  886. *
  887. * @internal ICU 75 technology preview
  888. * @deprecated This API is for technology preview only.
  889. */
  890. Builder(UErrorCode& status);
  891. /**
  892. * Destructor.
  893. *
  894. * @internal ICU 75 technology preview
  895. * @deprecated This API is for technology preview only.
  896. */
  897. virtual ~Builder();
  898. Builder(const Builder&) = delete;
  899. Builder& operator=(const Builder&) = delete;
  900. Builder(Builder&&) = delete;
  901. Builder& operator=(Builder&&) = delete;
  902. }; // class Operator::Builder
  903. /**
  904. * Copy constructor.
  905. *
  906. * @internal ICU 75 technology preview
  907. * @deprecated This API is for technology preview only.
  908. */
  909. Operator(const Operator& other) noexcept;
  910. /**
  911. * Non-member swap function.
  912. * @param o1 will get o2's contents
  913. * @param o2 will get o1's contents
  914. *
  915. * @internal ICU 75 technology preview
  916. * @deprecated This API is for technology preview only.
  917. */
  918. friend inline void swap(Operator& o1, Operator& o2) noexcept {
  919. using std::swap;
  920. swap(o1.name, o2.name);
  921. swap(o1.options, o2.options);
  922. }
  923. /**
  924. * Assignment operator.
  925. *
  926. * @internal ICU 75 technology preview
  927. * @deprecated This API is for technology preview only.
  928. */
  929. Operator& operator=(Operator) noexcept;
  930. /**
  931. * Default constructor.
  932. * Puts the Operator into a valid but undefined state.
  933. *
  934. * @internal ICU 75 technology preview
  935. * @deprecated This API is for technology preview only.
  936. */
  937. Operator() {}
  938. /**
  939. * Destructor.
  940. *
  941. * @internal ICU 75 technology preview
  942. * @deprecated This API is for technology preview only.
  943. */
  944. virtual ~Operator();
  945. private:
  946. friend class Binding;
  947. friend class Builder;
  948. friend class message2::Checker;
  949. friend class message2::MessageFormatter;
  950. friend class message2::Serializer;
  951. // Function call constructor
  952. Operator(const FunctionName& f, const UVector& options, UErrorCode&);
  953. const OptionMap& getOptionsInternal() const;
  954. Operator(const FunctionName&, const OptionMap&);
  955. /* const */ FunctionName name;
  956. /* const */ OptionMap options;
  957. }; // class Operator
  958. } // namespace data_model
  959. } // namespace message2
  960. U_NAMESPACE_END
  961. /// @cond DOXYGEN_IGNORE
  962. // Export an explicit template instantiation of the std::optional that is used as a
  963. // data member of various MFDataModel classes.
  964. // (When building DLLs for Windows this is required.)
  965. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  966. // for similar examples.)
  967. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  968. template class U_I18N_API std::optional<icu::message2::data_model::Operator>;
  969. #endif
  970. /// @endcond
  971. U_NAMESPACE_BEGIN
  972. namespace message2 {
  973. namespace data_model {
  974. // Internal only
  975. typedef enum UMarkupType {
  976. UMARKUP_OPEN = 0,
  977. UMARKUP_CLOSE,
  978. UMARKUP_STANDALONE,
  979. UMARKUP_COUNT
  980. } UMarkupType;
  981. /**
  982. * The `Markup` class corresponds to the `markup` nonterminal in the MessageFormat 2
  983. * grammar and the `markup` interface defined in
  984. * https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model/message.json
  985. *
  986. * `Markup` is immutable, copyable and movable.
  987. *
  988. * @internal ICU 75 technology preview
  989. * @deprecated This API is for technology preview only.
  990. */
  991. class U_I18N_API Markup : public UObject {
  992. public:
  993. /**
  994. * Checks if this markup is an opening tag.
  995. *
  996. * @return True if and only if this represents an opening tag.
  997. *
  998. * @internal ICU 75 technology preview
  999. * @deprecated This API is for technology preview only.
  1000. */
  1001. UBool isOpen() const { return (type == UMARKUP_OPEN); }
  1002. /**
  1003. * Checks if this markup is an closing tag.
  1004. *
  1005. * @return True if and only if this represents an closing tag.
  1006. *
  1007. * @internal ICU 75 technology preview
  1008. * @deprecated This API is for technology preview only.
  1009. */
  1010. UBool isClose() const { return (type == UMARKUP_CLOSE); }
  1011. /**
  1012. * Checks if this markup is an standalone tag.
  1013. *
  1014. * @return True if and only if this represents a standalone tag.
  1015. *
  1016. * @internal ICU 75 technology preview
  1017. * @deprecated This API is for technology preview only.
  1018. */
  1019. UBool isStandalone() const { return (type == UMARKUP_STANDALONE); }
  1020. /**
  1021. * Gets the name of this markup
  1022. *
  1023. * @return A reference to the string identifying the markup
  1024. *
  1025. * @internal ICU 75 technology preview
  1026. * @deprecated This API is for technology preview only.
  1027. */
  1028. const UnicodeString& getName() const { return name; }
  1029. /**
  1030. * Gets the options of this markup
  1031. *
  1032. * @return A reference to the string identifying the markup
  1033. *
  1034. * @internal ICU 75 technology preview
  1035. * @deprecated This API is for technology preview only.
  1036. */
  1037. std::vector<Option> getOptions() const { return options.getOptions(); }
  1038. /**
  1039. * Gets the attributes of this markup
  1040. *
  1041. * @return A vector of attributes
  1042. *
  1043. * @internal ICU 75 technology preview
  1044. * @deprecated This API is for technology preview only.
  1045. */
  1046. std::vector<Option> getAttributes() const { return attributes.getOptions(); }
  1047. /**
  1048. * Default constructor.
  1049. * Puts the Markup into a valid but undefined state.
  1050. *
  1051. * @internal ICU 75 technology preview
  1052. * @deprecated This API is for technology preview only.
  1053. */
  1054. Markup() {}
  1055. /**
  1056. * Destructor.
  1057. *
  1058. * @internal ICU 75 technology preview
  1059. * @deprecated This API is for technology preview only.
  1060. */
  1061. virtual ~Markup();
  1062. /**
  1063. * The mutable `Markup::Builder` class allows the markup to be constructed
  1064. * incrementally.
  1065. *
  1066. * Builder is not copyable or movable.
  1067. *
  1068. * @internal ICU 75 technology preview
  1069. * @deprecated This API is for technology preview only.
  1070. */
  1071. class U_I18N_API Builder : public UMemory {
  1072. private:
  1073. friend class Markup;
  1074. UnicodeString name;
  1075. OptionMap::Builder options;
  1076. OptionMap::Builder attributes;
  1077. UMarkupType type = UMARKUP_COUNT;
  1078. public:
  1079. /**
  1080. * Sets the name of this markup.
  1081. *
  1082. * @param n A string representing the name.
  1083. * @return A reference to the builder.
  1084. *
  1085. * @internal ICU 75 technology preview
  1086. * @deprecated This API is for technology preview only.
  1087. */
  1088. Builder& setName(const UnicodeString& n) { name = n; return *this; }
  1089. /**
  1090. * Sets this to be an opening markup.
  1091. *
  1092. * @return A reference to the builder.
  1093. *
  1094. * @internal ICU 75 technology preview
  1095. * @deprecated This API is for technology preview only.
  1096. */
  1097. Builder& setOpen() { type = UMARKUP_OPEN; return *this; }
  1098. /**
  1099. * Sets this to be an closing markup.
  1100. *
  1101. * @return A reference to the builder.
  1102. *
  1103. * @internal ICU 75 technology preview
  1104. * @deprecated This API is for technology preview only.
  1105. */
  1106. Builder& setClose() { type = UMARKUP_CLOSE; return *this; }
  1107. /**
  1108. * Sets this to be a standalone markup.
  1109. *
  1110. * @return A reference to the builder.
  1111. *
  1112. * @internal ICU 75 technology preview
  1113. * @deprecated This API is for technology preview only.
  1114. */
  1115. Builder& setStandalone() { type = UMARKUP_STANDALONE; return *this; }
  1116. /**
  1117. * Adds a single option.
  1118. *
  1119. * @param key The name of the option.
  1120. * @param value The value (right-hand side) of the option.
  1121. * @param status Input/output error code.
  1122. * @return A reference to the builder.
  1123. *
  1124. * @internal ICU 75 technology preview
  1125. * @deprecated This API is for technology preview only.
  1126. */
  1127. Builder& addOption(const UnicodeString &key, Operand&& value, UErrorCode& status);
  1128. /**
  1129. * Adds a single attribute.
  1130. *
  1131. * @param key The name of the attribute.
  1132. * @param value The value (right-hand side) of the attribute.
  1133. * @param status Input/output error code.
  1134. * @return A reference to the builder.
  1135. *
  1136. * @internal ICU 75 technology preview
  1137. * @deprecated This API is for technology preview only.
  1138. */
  1139. Builder& addAttribute(const UnicodeString &key, Operand&& value, UErrorCode& status);
  1140. /**
  1141. * Constructs a new immutable `Markup` using the name and type
  1142. * and (optionally) options and attributes that were previously set.
  1143. * If `setName()` and at least one of `setOpen()`, `setClose()`, and `setStandalone()`
  1144. * were not previously called,
  1145. * then `status` is set to U_INVALID_STATE_ERROR.
  1146. *
  1147. * The builder object (`this`) can still be used after calling `build()`.
  1148. * The `build()` method is non-const for internal implementation reasons,
  1149. * but is observably const.
  1150. *
  1151. * @param status Input/output error code.
  1152. * @return The new Markup.
  1153. *
  1154. * @internal ICU 75 technology preview
  1155. * @deprecated This API is for technology preview only.
  1156. */
  1157. Markup build(UErrorCode& status);
  1158. /**
  1159. * Default constructor.
  1160. * Returns a Builder with no name, type, options, or attributes set.
  1161. *
  1162. * @param status Input/output error code.
  1163. *
  1164. * @internal ICU 75 technology preview
  1165. * @deprecated This API is for technology preview only.
  1166. */
  1167. Builder(UErrorCode& status);
  1168. /**
  1169. * Destructor.
  1170. *
  1171. * @internal ICU 75 technology preview
  1172. * @deprecated This API is for technology preview only.
  1173. */
  1174. virtual ~Builder();
  1175. Builder(const Builder&) = delete;
  1176. Builder& operator=(const Builder&) = delete;
  1177. Builder(Builder&&) = delete;
  1178. Builder& operator=(Builder&&) = delete;
  1179. }; // class Markup::Builder
  1180. private:
  1181. friend class Builder;
  1182. friend class message2::Serializer;
  1183. UMarkupType type;
  1184. UnicodeString name;
  1185. OptionMap options;
  1186. OptionMap attributes;
  1187. const OptionMap& getOptionsInternal() const { return options; }
  1188. const OptionMap& getAttributesInternal() const { return attributes; }
  1189. Markup(UMarkupType, UnicodeString, OptionMap&&, OptionMap&&);
  1190. }; // class Markup
  1191. /**
  1192. * The `Expression` class corresponds to the `expression` nonterminal in the MessageFormat 2
  1193. * grammar and the `Expression` interface defined in
  1194. * https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#patterns
  1195. *
  1196. * It represents either an operand with no annotation; an annotation with no operand;
  1197. * or an operand annotated with an annotation.
  1198. *
  1199. * `Expression` is immutable, copyable and movable.
  1200. *
  1201. * @internal ICU 75 technology preview
  1202. * @deprecated This API is for technology preview only.
  1203. */
  1204. class U_I18N_API Expression : public UObject {
  1205. public:
  1206. /**
  1207. * Checks if this expression is an annotation
  1208. * with no operand.
  1209. *
  1210. * @return True if and only if the expression has
  1211. * an annotation and has no operand.
  1212. *
  1213. * @internal ICU 75 technology preview
  1214. * @deprecated This API is for technology preview only.
  1215. */
  1216. UBool isStandaloneAnnotation() const;
  1217. /**
  1218. * Checks if this expression has a function
  1219. * annotation (with or without an operand).
  1220. *
  1221. * @return True if and only if the expression has an annotation
  1222. * that is a function.
  1223. *
  1224. * @internal ICU 75 technology preview
  1225. * @deprecated This API is for technology preview only.
  1226. */
  1227. UBool isFunctionCall() const;
  1228. /**
  1229. * Accesses the function
  1230. * annotating this expression.
  1231. * If !(isFunctionCall()), sets
  1232. * `status` to U_INVALID_STATE_ERROR.
  1233. *
  1234. * @param status Input/output error code.
  1235. * @return A non-owned pointer to the operator of this expression,
  1236. * which does not outlive the expression.
  1237. *
  1238. * @internal ICU 75 technology preview
  1239. * @deprecated This API is for technology preview only.
  1240. */
  1241. const Operator* getOperator(UErrorCode& status) const;
  1242. /**
  1243. * Accesses the operand of this expression.
  1244. *
  1245. * @return A reference to the operand of this expression,
  1246. * which may be the null operand.
  1247. *
  1248. * @internal ICU 75 technology preview
  1249. * @deprecated This API is for technology preview only.
  1250. */
  1251. const Operand& getOperand() const;
  1252. /**
  1253. * Gets the attributes of this expression
  1254. *
  1255. * @return A vector of attributes
  1256. *
  1257. * @internal ICU 75 technology preview
  1258. * @deprecated This API is for technology preview only.
  1259. */
  1260. std::vector<Option> getAttributes() const { return attributes.getOptions(); }
  1261. /**
  1262. * The mutable `Expression::Builder` class allows the operator to be constructed
  1263. * incrementally.
  1264. *
  1265. * Builder is not copyable or movable.
  1266. *
  1267. * @internal ICU 75 technology preview
  1268. * @deprecated This API is for technology preview only.
  1269. */
  1270. class U_I18N_API Builder : public UMemory {
  1271. private:
  1272. friend class Expression;
  1273. bool hasOperand = false;
  1274. bool hasOperator = false;
  1275. Operand rand;
  1276. Operator rator;
  1277. OptionMap::Builder attributes;
  1278. public:
  1279. /**
  1280. * Sets the operand of this expression.
  1281. *
  1282. * @param rAnd The operand to set. Passed by move.
  1283. * @return A reference to the builder.
  1284. *
  1285. * @internal ICU 75 technology preview
  1286. * @deprecated This API is for technology preview only.
  1287. */
  1288. Builder& setOperand(Operand&& rAnd);
  1289. /**
  1290. * Sets the operator of this expression.
  1291. *
  1292. * @param rAtor The operator to set. Passed by move.
  1293. * @return A reference to the builder.
  1294. *
  1295. * @internal ICU 75 technology preview
  1296. * @deprecated This API is for technology preview only.
  1297. */
  1298. Builder& setOperator(Operator&& rAtor);
  1299. /**
  1300. * Adds a single attribute.
  1301. *
  1302. * @param key The name of the attribute.
  1303. * @param value The value (right-hand side) of the attribute.
  1304. * @param status Input/output error code.
  1305. * @return A reference to the builder.
  1306. *
  1307. * @internal ICU 75 technology preview
  1308. * @deprecated This API is for technology preview only.
  1309. */
  1310. Builder& addAttribute(const UnicodeString &key, Operand&& value, UErrorCode& status);
  1311. /**
  1312. * Constructs a new immutable `Expression` using the operand and operator that
  1313. * were previously set. If neither `setOperand()` nor `setOperator()` was
  1314. * previously called, or if `setOperand()` was called with the null operand
  1315. * and `setOperator()` was never called, then `status` is set to
  1316. * U_INVALID_STATE_ERROR.
  1317. *
  1318. * The builder object (`this`) can still be used after calling `build()`.
  1319. * The `build()` method is non-const for internal implementation reasons,
  1320. * but is observably const.
  1321. * @param status Input/output error code.
  1322. * @return The new Expression.
  1323. *
  1324. * @internal ICU 75 technology preview
  1325. * @deprecated This API is for technology preview only.
  1326. */
  1327. Expression build(UErrorCode& status);
  1328. /**
  1329. * Default constructor.
  1330. * Returns a Builder with no operator or operand set.
  1331. *
  1332. * @param status Input/output error code.
  1333. *
  1334. * @internal ICU 75 technology preview
  1335. * @deprecated This API is for technology preview only.
  1336. */
  1337. Builder(UErrorCode& status);
  1338. /**
  1339. * Destructor.
  1340. *
  1341. * @internal ICU 75 technology preview
  1342. * @deprecated This API is for technology preview only.
  1343. */
  1344. virtual ~Builder();
  1345. Builder(const Builder&) = delete;
  1346. Builder& operator=(const Builder&) = delete;
  1347. Builder(Builder&&) = delete;
  1348. Builder& operator=(Builder&&) = delete;
  1349. }; // class Expression::Builder
  1350. /**
  1351. * Non-member swap function.
  1352. * @param e1 will get e2's contents
  1353. * @param e2 will get e1's contents
  1354. *
  1355. * @internal ICU 75 technology preview
  1356. * @deprecated This API is for technology preview only.
  1357. */
  1358. friend inline void swap(Expression& e1, Expression& e2) noexcept {
  1359. using std::swap;
  1360. swap(e1.rator, e2.rator);
  1361. swap(e1.rand, e2.rand);
  1362. swap(e1.attributes, e2.attributes);
  1363. }
  1364. /**
  1365. * Copy constructor.
  1366. *
  1367. * @internal ICU 75 technology preview
  1368. * @deprecated This API is for technology preview only.
  1369. */
  1370. Expression(const Expression& other);
  1371. /**
  1372. * Assignment operator.
  1373. *
  1374. * @internal ICU 75 technology preview
  1375. * @deprecated This API is for technology preview only.
  1376. */
  1377. Expression& operator=(Expression) noexcept;
  1378. /**
  1379. * Default constructor.
  1380. * Puts the Expression into a valid but undefined state.
  1381. *
  1382. * @internal ICU 75 technology preview
  1383. * @deprecated This API is for technology preview only.
  1384. */
  1385. Expression();
  1386. /**
  1387. * Destructor.
  1388. *
  1389. * @internal ICU 75 technology preview
  1390. * @deprecated This API is for technology preview only.
  1391. */
  1392. virtual ~Expression();
  1393. private:
  1394. friend class message2::Serializer;
  1395. /*
  1396. Internally, an expression is represented as the application of an optional operator to an operand.
  1397. The operand is always present; for function calls with no operand, it's represented
  1398. as an operand for which `isNull()` is true.
  1399. Operator | Operand
  1400. --------------------------------
  1401. { |42| :fun opt=value } => (FunctionName=fun, | Literal(quoted=true, contents="42")
  1402. options={opt: value})
  1403. { abcd } => null | Literal(quoted=false, contents="abcd")
  1404. { : fun opt=value } => (FunctionName=fun,
  1405. options={opt: value}) | NullOperand()
  1406. */
  1407. Expression(const Operator &rAtor, const Operand &rAnd, const OptionMap& attrs) : rator(rAtor), rand(rAnd), attributes(attrs) {}
  1408. Expression(const Operand &rAnd, const OptionMap& attrs) : rator(std::nullopt), rand(Operand(rAnd)), attributes(attrs) {}
  1409. Expression(const Operator &rAtor, const OptionMap& attrs) : rator(rAtor), rand(), attributes(attrs) {}
  1410. /* const */ std::optional<Operator> rator;
  1411. /* const */ Operand rand;
  1412. /* const */ OptionMap attributes;
  1413. const OptionMap& getAttributesInternal() const { return attributes; }
  1414. }; // class Expression
  1415. } // namespace data_model
  1416. } // namespace message2
  1417. /// @cond DOXYGEN_IGNORE
  1418. // Export an explicit template instantiation of the LocalPointer that is used as a
  1419. // data member of various MFDataModel classes.
  1420. // (When building DLLs for Windows this is required.)
  1421. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  1422. // for similar examples.)
  1423. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  1424. template class U_I18N_API LocalPointerBase<message2::data_model::Expression>;
  1425. template class U_I18N_API LocalArray<message2::data_model::Expression>;
  1426. #endif
  1427. /// @endcond
  1428. namespace message2 {
  1429. namespace data_model {
  1430. class Pattern;
  1431. // Despite the comments, `PatternPart` is internal-only
  1432. /**
  1433. * A `PatternPart` is a single element (text or expression) in a `Pattern`.
  1434. * It corresponds to the `body` field of the `Pattern` interface
  1435. * defined in https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#patterns
  1436. *
  1437. * `PatternPart` is immutable, copyable and movable.
  1438. *
  1439. * @internal ICU 75 technology preview
  1440. * @deprecated This API is for technology preview only.
  1441. */
  1442. class PatternPart : public UObject {
  1443. public:
  1444. /**
  1445. * Checks if the part is a text part.
  1446. *
  1447. * @return True if and only if this is a text part.
  1448. *
  1449. * @internal ICU 75 technology preview
  1450. * @deprecated This API is for technology preview only.
  1451. */
  1452. UBool isText() const { return std::holds_alternative<UnicodeString>(piece); }
  1453. /**
  1454. * Checks if the part is a markup part.
  1455. *
  1456. * @return True if and only if this is a markup part.
  1457. *
  1458. * @internal ICU 75 technology preview
  1459. * @deprecated This API is for technology preview only.
  1460. */
  1461. UBool isMarkup() const { return std::holds_alternative<Markup>(piece); }
  1462. /**
  1463. * Checks if the part is an expression part.
  1464. *
  1465. * @return True if and only if this is an expression part.
  1466. *
  1467. * @internal ICU 75 technology preview
  1468. * @deprecated This API is for technology preview only.
  1469. */
  1470. UBool isExpression() const { return std::holds_alternative<Expression>(piece); }
  1471. /**
  1472. * Accesses the expression of the part.
  1473. * Precondition: isExpression()
  1474. *
  1475. * @return A reference to the part's underlying expression.
  1476. *
  1477. * @internal ICU 75 technology preview
  1478. * @deprecated This API is for technology preview only.
  1479. */
  1480. const Expression& contents() const;
  1481. /**
  1482. * Accesses the expression of the part.
  1483. * Precondition: isMarkup()
  1484. *
  1485. * @return A reference to the part's underlying expression.
  1486. *
  1487. * @internal ICU 75 technology preview
  1488. * @deprecated This API is for technology preview only.
  1489. */
  1490. const Markup& asMarkup() const;
  1491. /**
  1492. * Accesses the text contents of the part.
  1493. * Precondition: isText()
  1494. *
  1495. * @return A reference to a string representing the part's text..
  1496. *
  1497. * @internal ICU 75 technology preview
  1498. * @deprecated This API is for technology preview only.
  1499. */
  1500. const UnicodeString& asText() const;
  1501. /**
  1502. * Non-member swap function.
  1503. * @param p1 will get p2's contents
  1504. * @param p2 will get p1's contents
  1505. *
  1506. * @internal ICU 75 technology preview
  1507. * @deprecated This API is for technology preview only.
  1508. */
  1509. friend inline void swap(PatternPart& p1, PatternPart& p2) noexcept {
  1510. using std::swap;
  1511. swap(p1.piece, p2.piece);
  1512. }
  1513. /**
  1514. * Copy constructor.
  1515. *
  1516. * @internal ICU 75 technology preview
  1517. * @deprecated This API is for technology preview only.
  1518. */
  1519. PatternPart(const PatternPart& other);
  1520. /**
  1521. * Assignment operator.
  1522. *
  1523. * @internal ICU 75 technology preview
  1524. * @deprecated This API is for technology preview only.
  1525. */
  1526. PatternPart& operator=(PatternPart) noexcept;
  1527. /**
  1528. * Destructor.
  1529. *
  1530. * @internal ICU 75 technology preview
  1531. * @deprecated This API is for technology preview only.
  1532. */
  1533. virtual ~PatternPart();
  1534. /**
  1535. * Text part constructor. Returns a text pattern part
  1536. * with text `t`.
  1537. *
  1538. * @param t A text string.
  1539. *
  1540. * @internal ICU 75 technology preview
  1541. * @deprecated This API is for technology preview only.
  1542. */
  1543. explicit PatternPart(const UnicodeString& t) : piece(t) {}
  1544. /**
  1545. * Expression part constructor. Returns an Expression pattern
  1546. * part with expression `e`.
  1547. *
  1548. * @param e An Expression.
  1549. *
  1550. * @internal ICU 75 technology preview
  1551. * @deprecated This API is for technology preview only.
  1552. */
  1553. explicit PatternPart(Expression&& e) : piece(e) {}
  1554. /**
  1555. * Markup part constructor. Returns a Markup pattern
  1556. * part with markup `m`
  1557. *
  1558. * @param m A Markup.
  1559. *
  1560. * @internal ICU 75 technology preview
  1561. * @deprecated This API is for technology preview only.
  1562. */
  1563. explicit PatternPart(Markup&& m) : piece(m) {}
  1564. /**
  1565. * Default constructor.
  1566. * Puts the PatternPart into a valid but undefined state.
  1567. *
  1568. * @internal ICU 75 technology preview
  1569. * @deprecated This API is for technology preview only.
  1570. */
  1571. PatternPart() = default;
  1572. private:
  1573. friend class Pattern;
  1574. std::variant<UnicodeString, Expression, Markup> piece;
  1575. }; // class PatternPart
  1576. } // namespace data_model
  1577. } // namespace message2
  1578. /// @cond DOXYGEN_IGNORE
  1579. // Export an explicit template instantiation of the LocalPointer that is used as a
  1580. // data member of various MFDataModel classes.
  1581. // (When building DLLs for Windows this is required.)
  1582. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  1583. // for similar examples.)
  1584. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  1585. template class U_I18N_API LocalPointerBase<message2::data_model::PatternPart>;
  1586. template class U_I18N_API LocalArray<message2::data_model::PatternPart>;
  1587. #endif
  1588. /// @endcond
  1589. namespace message2 {
  1590. namespace data_model {
  1591. /**
  1592. * A `Pattern` is a sequence of formattable parts.
  1593. * It corresponds to the `Pattern` interface
  1594. * defined in https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#patterns
  1595. *
  1596. * `Pattern` is immutable, copyable and movable.
  1597. *
  1598. * @internal ICU 75 technology preview
  1599. * @deprecated This API is for technology preview only.
  1600. */
  1601. class U_I18N_API Pattern : public UObject {
  1602. private:
  1603. friend class PatternPart;
  1604. public:
  1605. struct Iterator;
  1606. /**
  1607. * Returns the parts of this pattern
  1608. *
  1609. * @return A forward iterator of variants. Each element is either a string (text part)
  1610. * or an expression part.
  1611. *
  1612. * @internal ICU 75 technology preview
  1613. * @deprecated This API is for technology preview only.
  1614. */
  1615. Iterator begin() const {
  1616. return Iterator(this, 0);
  1617. }
  1618. /**
  1619. * Returns a special value to mark the end of iteration
  1620. *
  1621. * @return A forward iterator of variants. This should only be used for comparisons
  1622. * against an iterator returned by incrementing begin().
  1623. *
  1624. * @internal ICU 75 technology preview
  1625. * @deprecated This API is for technology preview only.
  1626. */
  1627. Iterator end() const {
  1628. return Iterator(this, len);
  1629. }
  1630. /**
  1631. * The mutable `Pattern::Builder` class allows the pattern to be
  1632. * constructed one part at a time.
  1633. *
  1634. * Builder is not copyable or movable.
  1635. *
  1636. * @internal ICU 75 technology preview
  1637. * @deprecated This API is for technology preview only.
  1638. */
  1639. class U_I18N_API Builder : public UMemory {
  1640. private:
  1641. friend class Pattern;
  1642. UVector* parts; // Not a LocalPointer for the same reason as in `SelectorKeys::Builder`
  1643. public:
  1644. /**
  1645. * Adds a single expression part to the pattern.
  1646. *
  1647. * @param part The part to be added (passed by move)
  1648. * @param status Input/output error code.
  1649. * @return A reference to the builder.
  1650. *
  1651. * @internal ICU 75 technology preview
  1652. * @deprecated This API is for technology preview only.
  1653. */
  1654. Builder& add(Expression&& part, UErrorCode& status) noexcept;
  1655. /**
  1656. * Adds a single markup part to the pattern.
  1657. *
  1658. * @param part The part to be added (passed by move)
  1659. * @param status Input/output error code.
  1660. * @return A reference to the builder.
  1661. *
  1662. * @internal ICU 75 technology preview
  1663. * @deprecated This API is for technology preview only.
  1664. */
  1665. Builder& add(Markup&& part, UErrorCode& status) noexcept;
  1666. /**
  1667. * Adds a single text part to the pattern. Copies `part`.
  1668. *
  1669. * @param part The part to be added (passed by move)
  1670. * @param status Input/output error code.
  1671. * @return A reference to the builder.
  1672. *
  1673. * @internal ICU 75 technology preview
  1674. * @deprecated This API is for technology preview only.
  1675. */
  1676. Builder& add(UnicodeString&& part, UErrorCode& status) noexcept;
  1677. /**
  1678. * Constructs a new immutable `Pattern` using the list of parts
  1679. * set with previous `add()` calls.
  1680. *
  1681. * The builder object (`this`) can still be used after calling `build()`.
  1682. *
  1683. * @param status Input/output error code.
  1684. * @return The pattern object
  1685. *
  1686. * @internal ICU 75 technology preview
  1687. * @deprecated This API is for technology preview only.
  1688. */
  1689. Pattern build(UErrorCode& status) const noexcept;
  1690. /**
  1691. * Default constructor.
  1692. * Returns a Builder with an empty sequence of PatternParts.
  1693. *
  1694. * @param status Input/output error code
  1695. *
  1696. * @internal ICU 75 technology preview
  1697. * @deprecated This API is for technology preview only.
  1698. */
  1699. Builder(UErrorCode& status);
  1700. /**
  1701. * Destructor.
  1702. *
  1703. * @internal ICU 75 technology preview
  1704. * @deprecated This API is for technology preview only.
  1705. */
  1706. virtual ~Builder();
  1707. Builder(const Builder&) = delete;
  1708. Builder& operator=(const Builder&) = delete;
  1709. Builder(Builder&&) = delete;
  1710. Builder& operator=(Builder&&) = delete;
  1711. }; // class Pattern::Builder
  1712. /**
  1713. * Default constructor.
  1714. * Puts the Pattern into a valid but undefined state.
  1715. *
  1716. * @internal ICU 75 technology preview
  1717. * @deprecated This API is for technology preview only.
  1718. */
  1719. Pattern() : parts(LocalArray<PatternPart>()) {}
  1720. /**
  1721. * Non-member swap function.
  1722. * @param p1 will get p2's contents
  1723. * @param p2 will get p1's contents
  1724. *
  1725. * @internal ICU 75 technology preview
  1726. * @deprecated This API is for technology preview only.
  1727. */
  1728. friend inline void swap(Pattern& p1, Pattern& p2) noexcept {
  1729. using std::swap;
  1730. swap(p1.bogus, p2.bogus);
  1731. swap(p1.len, p2.len);
  1732. swap(p1.parts, p2.parts);
  1733. }
  1734. /**
  1735. * Copy constructor.
  1736. *
  1737. * @internal ICU 75 technology preview
  1738. * @deprecated This API is for technology preview only.
  1739. */
  1740. Pattern(const Pattern& other);
  1741. /**
  1742. * Assignment operator
  1743. *
  1744. * @internal ICU 75 technology preview
  1745. * @deprecated This API is for technology preview only.
  1746. */
  1747. Pattern& operator=(Pattern) noexcept;
  1748. /**
  1749. * Destructor.
  1750. *
  1751. * @internal ICU 75 technology preview
  1752. * @deprecated This API is for technology preview only.
  1753. */
  1754. virtual ~Pattern();
  1755. /**
  1756. * The `Pattern::Iterator` class provides an iterator over the formattable
  1757. * parts of a pattern.
  1758. *
  1759. * `Pattern::Iterator` is mutable and is not copyable or movable.
  1760. *
  1761. * @internal ICU 75 technology preview
  1762. * @deprecated This API is for technology preview only.
  1763. */
  1764. struct U_I18N_API Iterator {
  1765. private:
  1766. using iterator_category = std::forward_iterator_tag;
  1767. using difference_type = std::ptrdiff_t;
  1768. using value_type = std::variant<UnicodeString, Expression, Markup>;
  1769. using pointer = value_type*;
  1770. using reference = const value_type&;
  1771. friend class Pattern;
  1772. Iterator(const Pattern* p, int32_t i) : pos(i), pat(p) {}
  1773. friend bool operator== (const Iterator& a, const Iterator& b) { return (a.pat == b.pat && a.pos == b.pos); }
  1774. int32_t pos;
  1775. const Pattern* pat;
  1776. public:
  1777. /**
  1778. * Dereference operator (gets the element at the current iterator position)
  1779. *
  1780. * @internal ICU 75 technology preview
  1781. * @deprecated This API is for technology preview only.
  1782. */
  1783. reference operator*() const {
  1784. const PatternPart& part = pat->parts[pos];
  1785. return patternContents(part);
  1786. }
  1787. /**
  1788. * Increment operator (advances to the next iterator position)
  1789. *
  1790. * @internal ICU 75 technology preview
  1791. * @deprecated This API is for technology preview only.
  1792. */
  1793. Iterator operator++() { pos++; return *this; }
  1794. /**
  1795. * Inequality comparison operator (used for comparing an iterator to the result of end())
  1796. *
  1797. * @internal ICU 75 technology preview
  1798. * @deprecated This API is for technology preview only.
  1799. */
  1800. friend bool operator!= (const Iterator& a, const Iterator& b) { return !(a == b); }
  1801. }; // struct Iterator
  1802. private:
  1803. friend class Builder;
  1804. friend class message2::MessageFormatter;
  1805. friend class message2::Serializer;
  1806. // Set to true if a copy constructor fails;
  1807. // needed in order to distinguish an uninitialized
  1808. // Pattern from a 0-length pattern
  1809. bool bogus = false;
  1810. // Possibly-empty array of parts
  1811. int32_t len = 0;
  1812. LocalArray<PatternPart> parts;
  1813. Pattern(const UVector& parts, UErrorCode& status);
  1814. // Helper
  1815. static void initParts(Pattern&, const Pattern&);
  1816. /**
  1817. * Returns the size.
  1818. *
  1819. * @return The number of parts in the pattern.
  1820. *
  1821. * @internal ICU 75 technology preview
  1822. * @deprecated This API is for technology preview only.
  1823. */
  1824. int32_t numParts() const;
  1825. /**
  1826. * Returns the `i`th part in the pattern.
  1827. * Precondition: i < numParts()
  1828. *
  1829. * @param i Index of the part being accessed.
  1830. * @return A reference to the part at index `i`.
  1831. *
  1832. * @internal ICU 75 technology preview
  1833. * @deprecated This API is for technology preview only.
  1834. */
  1835. const PatternPart& getPart(int32_t i) const;
  1836. // Gets around not being able to declare Pattern::Iterator as a friend
  1837. // in PatternPart
  1838. static const std::variant<UnicodeString, Expression, Markup>&
  1839. patternContents(const PatternPart& p) { return p.piece; }
  1840. }; // class Pattern
  1841. /**
  1842. * A `Variant` pairs a list of keys with a pattern
  1843. * It corresponds to the `Variant` interface
  1844. * defined in https://github.com/unicode-org/message-format-wg/tree/main/spec/data-model
  1845. *
  1846. * `Variant` is immutable, copyable and movable.
  1847. *
  1848. * @internal ICU 75 technology preview
  1849. * @deprecated This API is for technology preview only.
  1850. */
  1851. class U_I18N_API Variant : public UObject {
  1852. public:
  1853. /**
  1854. * Accesses the pattern of the variant.
  1855. *
  1856. * @return A reference to the pattern.
  1857. *
  1858. * @internal ICU 75 technology preview
  1859. * @deprecated This API is for technology preview only.
  1860. */
  1861. const Pattern& getPattern() const { return p; }
  1862. /**
  1863. * Accesses the keys of the variant.
  1864. *
  1865. * @return A reference to the keys.
  1866. *
  1867. * @internal ICU 75 technology preview
  1868. * @deprecated This API is for technology preview only.
  1869. */
  1870. const SelectorKeys& getKeys() const { return k; }
  1871. /**
  1872. * Constructor. Returns a variant that formats to `pattern`
  1873. * when `keys` match the selector expressions in the enclosing
  1874. * `match` construct.
  1875. *
  1876. * @param keys A reference to a `SelectorKeys`.
  1877. * @param pattern A pattern (passed by move)
  1878. *
  1879. * @internal ICU 75 technology preview
  1880. * @deprecated This API is for technology preview only.
  1881. */
  1882. Variant(const SelectorKeys& keys, Pattern&& pattern) : k(keys), p(std::move(pattern)) {}
  1883. /**
  1884. * Non-member swap function.
  1885. * @param v1 will get v2's contents
  1886. * @param v2 will get v1's contents
  1887. *
  1888. * @internal ICU 75 technology preview
  1889. * @deprecated This API is for technology preview only.
  1890. */
  1891. friend inline void swap(Variant& v1, Variant& v2) noexcept {
  1892. using std::swap;
  1893. swap(v1.k, v2.k);
  1894. swap(v1.p, v2.p);
  1895. }
  1896. /**
  1897. * Assignment operator
  1898. *
  1899. * @internal ICU 75 technology preview
  1900. * @deprecated This API is for technology preview only.
  1901. */
  1902. Variant& operator=(Variant other) noexcept;
  1903. /**
  1904. * Default constructor.
  1905. * Returns a Variant in a valid but undefined state.
  1906. *
  1907. * @internal ICU 75 technology preview
  1908. * @deprecated This API is for technology preview only.
  1909. */
  1910. Variant() = default;
  1911. /**
  1912. * Copy constructor.
  1913. *
  1914. * @internal ICU 75 technology preview
  1915. * @deprecated This API is for technology preview only.
  1916. */
  1917. Variant(const Variant&);
  1918. /**
  1919. * Destructor.
  1920. *
  1921. * @internal ICU 75 technology preview
  1922. * @deprecated This API is for technology preview only.
  1923. */
  1924. virtual ~Variant();
  1925. private:
  1926. /* const */ SelectorKeys k;
  1927. /* const */ Pattern p;
  1928. }; // class Variant
  1929. } // namespace data_model
  1930. namespace data_model {
  1931. /**
  1932. * A `Binding` pairs a variable name with an expression.
  1933. * It corresponds to the `Declaration` interface
  1934. * defined in https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md#messages
  1935. *
  1936. * `Binding` is immutable and copyable. It is not movable.
  1937. *
  1938. * @internal ICU 75 technology preview
  1939. * @deprecated This API is for technology preview only.
  1940. */
  1941. class U_I18N_API Binding : public UObject {
  1942. public:
  1943. /**
  1944. * Accesses the right-hand side of a binding.
  1945. *
  1946. * @return A reference to the expression.
  1947. *
  1948. * @internal ICU 75 technology preview
  1949. * @deprecated This API is for technology preview only.
  1950. */
  1951. const Expression& getValue() const;
  1952. /**
  1953. * Accesses the left-hand side of the binding.
  1954. *
  1955. * @return A reference to the variable name.
  1956. *
  1957. * @internal ICU 75 technology preview
  1958. * @deprecated This API is for technology preview only.
  1959. */
  1960. const VariableName& getVariable() const { return var; }
  1961. /**
  1962. * Constructor for input binding.
  1963. *
  1964. * @param variableName The variable name (left-hand side) of the binding. Passed by move.
  1965. * @param rhs The right-hand side of the input binding. Passed by move.
  1966. * `rhs` must have an operand that is a variable reference to `variableName`.
  1967. * If `rhs` has an operator, it must be a function call.
  1968. * If either of these properties is violated, `errorCode` is set to
  1969. * U_INVALID_STATE_ERROR.
  1970. * @param errorCode Input/output error code
  1971. *
  1972. * @internal ICU 75 technology preview
  1973. * @deprecated This API is for technology preview only.
  1974. */
  1975. static Binding input(UnicodeString&& variableName, Expression&& rhs, UErrorCode& errorCode);
  1976. /**
  1977. * Returns true if and only if this binding represents a local declaration.
  1978. * Otherwise, it's an input declaration.
  1979. *
  1980. * @return True if this binding represents a variable and expression;
  1981. * false if it represents a variable plus an annotation.
  1982. */
  1983. UBool isLocal() const { return local; }
  1984. /**
  1985. * Constructor.
  1986. *
  1987. * @param v A variable name.
  1988. * @param e An expression.
  1989. *
  1990. * @internal ICU 75 technology preview
  1991. * @deprecated This API is for technology preview only.
  1992. */
  1993. Binding(const VariableName& v, Expression&& e) : var(v), expr(std::move(e)), local(true), annotation(nullptr) {}
  1994. /**
  1995. * Non-member swap function.
  1996. * @param b1 will get b2's contents
  1997. * @param b2 will get b1's contents
  1998. *
  1999. * @internal ICU 75 technology preview
  2000. * @deprecated This API is for technology preview only.
  2001. */
  2002. friend inline void swap(Binding& b1, Binding& b2) noexcept {
  2003. using std::swap;
  2004. swap(b1.var, b2.var);
  2005. swap(b1.expr, b2.expr);
  2006. swap(b1.local, b2.local);
  2007. b1.updateAnnotation();
  2008. b2.updateAnnotation();
  2009. }
  2010. /**
  2011. * Copy constructor.
  2012. *
  2013. * @internal ICU 75 technology preview
  2014. * @deprecated This API is for technology preview only.
  2015. */
  2016. Binding(const Binding& other);
  2017. /**
  2018. * Copy assignment operator
  2019. *
  2020. * @internal ICU 75 technology preview
  2021. * @deprecated This API is for technology preview only.
  2022. */
  2023. Binding& operator=(Binding) noexcept;
  2024. /**
  2025. * Default constructor.
  2026. * Puts the Binding into a valid but undefined state.
  2027. *
  2028. * @internal ICU 75 technology preview
  2029. * @deprecated This API is for technology preview only.
  2030. */
  2031. Binding() : local(true) {}
  2032. /**
  2033. * Destructor.
  2034. *
  2035. * @internal ICU 75 technology preview
  2036. * @deprecated This API is for technology preview only.
  2037. */
  2038. virtual ~Binding();
  2039. private:
  2040. friend class message2::Checker;
  2041. friend class message2::MessageFormatter;
  2042. friend class message2::Parser;
  2043. friend class message2::Serializer;
  2044. /* const */ VariableName var;
  2045. /* const */ Expression expr;
  2046. /* const */ bool local;
  2047. // The following field is always nullptr for a local
  2048. // declaration, and possibly nullptr for an .input declaration
  2049. // If non-null, the referent is a member of `expr` so
  2050. // its lifetime is the same as the lifetime of the enclosing Binding
  2051. // (as long as there's no mutation)
  2052. const Operator* annotation = nullptr;
  2053. const OptionMap& getOptionsInternal() const;
  2054. bool hasAnnotation() const { return !local && (annotation != nullptr); }
  2055. void updateAnnotation();
  2056. }; // class Binding
  2057. } // namespace data_model
  2058. } // namespace message2
  2059. /// @cond DOXYGEN_IGNORE
  2060. // Export an explicit template instantiation of the LocalPointer that is used as a
  2061. // data member of various MFDataModel classes.
  2062. // (When building DLLs for Windows this is required.)
  2063. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  2064. // for similar examples.)
  2065. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  2066. template class U_I18N_API LocalPointerBase<message2::data_model::Variant>;
  2067. template class U_I18N_API LocalPointerBase<message2::data_model::Binding>;
  2068. template class U_I18N_API LocalArray<message2::data_model::Variant>;
  2069. template class U_I18N_API LocalArray<message2::data_model::Binding>;
  2070. #endif
  2071. /// @endcond
  2072. namespace message2 {
  2073. using namespace data_model;
  2074. // Internal only
  2075. class MFDataModel;
  2076. #ifndef U_IN_DOXYGEN
  2077. class Matcher : public UObject {
  2078. public:
  2079. Matcher& operator=(Matcher);
  2080. Matcher(const Matcher&);
  2081. /**
  2082. * Non-member swap function.
  2083. * @param m1 will get m2's contents
  2084. * @param m2 will get m1's contents
  2085. *
  2086. * @internal ICU 75 technology preview
  2087. * @deprecated This API is for technology preview only.
  2088. */
  2089. friend inline void swap(Matcher& m1, Matcher& m2) noexcept {
  2090. using std::swap;
  2091. if (m1.bogus) {
  2092. m2.bogus = true;
  2093. return;
  2094. }
  2095. if (m2.bogus) {
  2096. m1.bogus = true;
  2097. return;
  2098. }
  2099. swap(m1.selectors, m2.selectors);
  2100. swap(m1.numSelectors, m2.numSelectors);
  2101. swap(m1.variants, m2.variants);
  2102. swap(m1.numVariants, m2.numVariants);
  2103. }
  2104. virtual ~Matcher();
  2105. private:
  2106. friend class MFDataModel;
  2107. Matcher(Expression* ss, int32_t ns, Variant* vs, int32_t nv);
  2108. Matcher() {}
  2109. // A Matcher may have numSelectors=0 and numVariants=0
  2110. // (this is a data model error, but it's representable).
  2111. // So we have to keep a separate flag to track failed copies.
  2112. bool bogus = false;
  2113. // The expressions that are being matched on.
  2114. LocalArray<Expression> selectors;
  2115. // The number of selectors
  2116. int32_t numSelectors = 0;
  2117. // The list of `when` clauses (case arms).
  2118. LocalArray<Variant> variants;
  2119. // The number of variants
  2120. int32_t numVariants = 0;
  2121. }; // class Matcher
  2122. #endif
  2123. } // namespace message2
  2124. U_NAMESPACE_END
  2125. /// @cond DOXYGEN_IGNORE
  2126. // Export an explicit template instantiation of the std::variant that is used as a
  2127. // data member of various MFDataModel classes.
  2128. // (When building DLLs for Windows this is required.)
  2129. // (See measunit_impl.h, datefmt.h, collationiterator.h, erarules.h and others
  2130. // for similar examples.)
  2131. #if U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN
  2132. #if defined(U_REAL_MSVC) && defined(_MSVC_STL_VERSION)
  2133. template class U_I18N_API std::_Variant_storage_<false, icu::message2::Matcher,icu::message2::data_model::Pattern>;
  2134. #endif
  2135. template class U_I18N_API std::variant<icu::message2::Matcher,icu::message2::data_model::Pattern>;
  2136. #endif
  2137. /// @endcond
  2138. U_NAMESPACE_BEGIN
  2139. namespace message2 {
  2140. // -----------------------------------------------------------------------
  2141. // Public MFDataModel class
  2142. /**
  2143. *
  2144. * The `MFDataModel` class describes a parsed representation of the text of a message.
  2145. * This representation is public as higher-level APIs for messages will need to know its public
  2146. * interface: for example, to re-instantiate a parsed message with different values for imported
  2147. variables.
  2148. *
  2149. * The MFDataModel API implements <a target="github"
  2150. href="https://github.com/unicode-org/message-format-wg/blob/main/spec/data-model.md">the
  2151. * specification of the abstract syntax (data model representation)</a> for MessageFormat.
  2152. *
  2153. * `MFDataModel` is immutable, copyable and movable.
  2154. *
  2155. * @internal ICU 75 technology preview
  2156. * @deprecated This API is for technology preview only.
  2157. */
  2158. class U_I18N_API MFDataModel : public UMemory {
  2159. /*
  2160. Classes that represent nodes in the data model are nested inside the
  2161. `MFDataModel` class.
  2162. Classes such as `Expression`, `Pattern` and `VariantMap` are immutable and
  2163. are constructed using the builder pattern.
  2164. Most classes representing nodes have copy constructors. This is because builders
  2165. contain immutable data that must be copied when calling `build()`, since the builder
  2166. could go out of scope before the immutable result of the builder does. Copying is
  2167. also necessary to prevent unexpected mutation if intermediate builders are saved
  2168. and mutated again after calling `build()`.
  2169. The copy constructors perform a deep copy, for example by copying the entire
  2170. list of options for an `Operator` (and copying the entire underlying vector.)
  2171. Some internal fields should be `const`, but are declared as non-`const` to make
  2172. the copy constructor simpler to implement. (These are noted throughout.) In
  2173. other words, those fields are `const` except during the execution of a copy
  2174. constructor.
  2175. On the other hand, intermediate `Builder` methods that return a `Builder&`
  2176. mutate the state of the builder, so in code like:
  2177. Expression::Builder& exprBuilder = Expression::builder()-> setOperand(foo);
  2178. Expression::Builder& exprBuilder2 = exprBuilder.setOperator(bar);
  2179. the call to `setOperator()` would mutate `exprBuilder`, since `exprBuilder`
  2180. and `exprBuilder2` are references to the same object.
  2181. An alternate choice would be to make `build()` destructive, so that copying would
  2182. be unnecessary. Or, both copying and moving variants of `build()` could be
  2183. provided. Copying variants of the intermediate `Builder` methods could be
  2184. provided as well, if this proved useful.
  2185. */
  2186. public:
  2187. /**
  2188. * Accesses the local variable declarations for this data model.
  2189. *
  2190. * @return A vector of bindings for local variables.
  2191. *
  2192. * @internal ICU 75 technology preview
  2193. * @deprecated This API is for technology preview only.
  2194. */
  2195. std::vector<Binding> getLocalVariables() const {
  2196. std::vector<Binding> result;
  2197. if (!bogus) {
  2198. return toStdVector<Binding>(bindings.getAlias(), bindingsLen);
  2199. }
  2200. return {};
  2201. }
  2202. /**
  2203. * Accesses the selectors. Returns an empty vector if this is a pattern message.
  2204. *
  2205. * @return A vector of selectors.
  2206. *
  2207. * @internal ICU 75 technology preview
  2208. * @deprecated This API is for technology preview only.
  2209. */
  2210. const std::vector<Expression> getSelectors() const {
  2211. if (std::holds_alternative<Pattern>(body)) {
  2212. return {};
  2213. }
  2214. const Matcher* match = std::get_if<Matcher>(&body);
  2215. // match must be non-null, given the previous check
  2216. return toStdVector<Expression>(match->selectors.getAlias(), match->numSelectors);
  2217. }
  2218. /**
  2219. * Accesses the variants. Returns an empty vector if this is a pattern message.
  2220. *
  2221. * @return A vector of variants.
  2222. *
  2223. * @internal ICU 75 technology preview
  2224. * @deprecated This API is for technology preview only.
  2225. */
  2226. std::vector<Variant> getVariants() const {
  2227. // Return empty vector if no variants
  2228. if (std::holds_alternative<Pattern>(body)) {
  2229. return {};
  2230. }
  2231. const Matcher* match = std::get_if<Matcher>(&body);
  2232. // match must be non-null, given the previous check
  2233. return toStdVector<Variant>(match->variants.getAlias(), match->numVariants);
  2234. return {};
  2235. }
  2236. /**
  2237. * Accesses the pattern (in a message without selectors).
  2238. * Returns a reference to an empty pattern if the message has selectors.
  2239. *
  2240. * @return A reference to the pattern.
  2241. *
  2242. * @internal ICU 75 technology preview
  2243. * @deprecated This API is for technology preview only.
  2244. */
  2245. const Pattern& getPattern() const;
  2246. /**
  2247. * The mutable `MFDataModel::Builder` class allows the data model to be
  2248. * constructed incrementally.
  2249. *
  2250. * @internal ICU 75 technology preview
  2251. * @deprecated This API is for technology preview only.
  2252. */
  2253. class U_I18N_API Builder;
  2254. /**
  2255. * Default constructor.
  2256. * Puts the MFDataModel into a valid but undefined state.
  2257. *
  2258. * @internal ICU 75 technology preview
  2259. * @deprecated This API is for technology preview only.
  2260. */
  2261. MFDataModel();
  2262. /**
  2263. * Non-member swap function.
  2264. * @param m1 will get m2's contents
  2265. * @param m2 will get m1's contents
  2266. *
  2267. * @internal ICU 75 technology preview
  2268. * @deprecated This API is for technology preview only.
  2269. */
  2270. friend inline void swap(MFDataModel& m1, MFDataModel& m2) noexcept {
  2271. using std::swap;
  2272. if (m1.bogus) {
  2273. m2.bogus = true;
  2274. return;
  2275. }
  2276. if (m2.bogus) {
  2277. m1.bogus = true;
  2278. return;
  2279. }
  2280. swap(m1.body, m2.body);
  2281. swap(m1.bindings, m2.bindings);
  2282. swap(m1.bindingsLen, m2.bindingsLen);
  2283. }
  2284. /**
  2285. * Assignment operator
  2286. *
  2287. * @internal ICU 75 technology preview
  2288. * @deprecated This API is for technology preview only.
  2289. */
  2290. MFDataModel& operator=(MFDataModel) noexcept;
  2291. /**
  2292. * Copy constructor.
  2293. *
  2294. * @internal ICU 75 technology preview
  2295. * @deprecated This API is for technology preview only.
  2296. */
  2297. MFDataModel(const MFDataModel& other);
  2298. /**
  2299. * Destructor.
  2300. *
  2301. * @internal ICU 75 technology preview
  2302. * @deprecated This API is for technology preview only.
  2303. */
  2304. virtual ~MFDataModel();
  2305. /**
  2306. * The mutable `MFDataModel::Builder` class allows the data model to be
  2307. * constructed incrementally. Builder is not copyable or movable.
  2308. *
  2309. * @internal ICU 75 technology preview
  2310. * @deprecated This API is for technology preview only.
  2311. */
  2312. class U_I18N_API Builder : public UMemory {
  2313. private:
  2314. friend class MFDataModel;
  2315. void checkDuplicate(const VariableName&, UErrorCode&) const;
  2316. void buildSelectorsMessage(UErrorCode&);
  2317. bool hasPattern = true;
  2318. bool hasSelectors = false;
  2319. Pattern pattern;
  2320. // The following members are not LocalPointers for the same reason as in SelectorKeys::Builder
  2321. UVector* selectors = nullptr;
  2322. UVector* variants = nullptr;
  2323. UVector* bindings = nullptr;
  2324. public:
  2325. /**
  2326. * Adds a binding, There must not already be a binding
  2327. * with the same name.
  2328. *
  2329. * @param b The binding. Passed by move.
  2330. * @param status Input/output error code. Set to U_DUPLICATE_DECLARATION_ERROR
  2331. * if `addBinding()` was previously called with a binding
  2332. * with the same variable name as `b`.
  2333. *
  2334. * @internal ICU 75 technology preview
  2335. * @deprecated This API is for technology preview only.
  2336. */
  2337. Builder& addBinding(Binding&& b, UErrorCode& status);
  2338. /**
  2339. * Adds a selector expression. Copies `expression`.
  2340. * If a pattern was previously set, clears the pattern.
  2341. *
  2342. * @param selector Expression to add as a selector. Passed by move.
  2343. * @param errorCode Input/output error code
  2344. * @return A reference to the builder.
  2345. *
  2346. * @internal ICU 75 technology preview
  2347. * @deprecated This API is for technology preview only.
  2348. */
  2349. Builder& addSelector(Expression&& selector, UErrorCode& errorCode) noexcept;
  2350. /**
  2351. * Adds a single variant.
  2352. * If a pattern was previously set using `setPattern()`, clears the pattern.
  2353. *
  2354. * @param keys Keys for the variant. Passed by move.
  2355. * @param pattern Pattern for the variant. Passed by move.
  2356. * @param errorCode Input/output error code
  2357. * @return A reference to the builder.
  2358. *
  2359. * @internal ICU 75 technology preview
  2360. * @deprecated This API is for technology preview only.
  2361. */
  2362. Builder& addVariant(SelectorKeys&& keys, Pattern&& pattern, UErrorCode& errorCode) noexcept;
  2363. /**
  2364. * Sets the body of the message as a pattern.
  2365. * If selectors and/or variants were previously set, clears them.
  2366. *
  2367. * @param pattern Pattern to represent the body of the message.
  2368. * Passed by move.
  2369. * @return A reference to the builder.
  2370. *
  2371. * @internal ICU 75 technology preview
  2372. * @deprecated This API is for technology preview only.
  2373. */
  2374. Builder& setPattern(Pattern&& pattern);
  2375. /**
  2376. * Constructs a new immutable data model.
  2377. * If `setPattern()` has not been called and if `addSelector()` and
  2378. * `addVariant()` were not each called at least once,
  2379. * `status` is set to `U_INVALID_STATE_ERROR`.
  2380. * If `addSelector()` was called and `addVariant()` was never called,
  2381. * or vice versa, then `status` is set to U_INVALID_STATE_ERROR.
  2382. * Otherwise, either a Pattern or Selectors message is constructed
  2383. * based on the pattern that was previously set, or selectors and variants
  2384. * that were previously set.
  2385. *
  2386. * The builder object (`this`) can still be used after calling `build()`.
  2387. *
  2388. * @param status Input/output error code.
  2389. * @return The new MFDataModel
  2390. *
  2391. * @internal ICU 75 technology preview
  2392. * @deprecated This API is for technology preview only.
  2393. */
  2394. MFDataModel build(UErrorCode& status) const noexcept;
  2395. /**
  2396. * Default constructor.
  2397. * Returns a Builder with no pattern or selectors set.
  2398. * Either `setPattern()` or both `addSelector()` and
  2399. * `addVariant()` must be called before calling `build()`
  2400. * on the resulting builder.
  2401. *
  2402. * @param status Input/output error code.
  2403. *
  2404. * @internal ICU 75 technology preview
  2405. * @deprecated This API is for technology preview only.
  2406. */
  2407. Builder(UErrorCode& status);
  2408. /**
  2409. * Destructor.
  2410. *
  2411. * @internal ICU 75 technology preview
  2412. * @deprecated This API is for technology preview only.
  2413. */
  2414. virtual ~Builder();
  2415. Builder(const Builder&) = delete;
  2416. Builder& operator=(const Builder&) = delete;
  2417. Builder(Builder&&) = delete;
  2418. Builder& operator=(Builder&&) = delete;
  2419. }; // class Builder
  2420. private:
  2421. friend class Checker;
  2422. friend class MessageFormatter;
  2423. friend class Serializer;
  2424. Pattern empty; // Provided so that `getPattern()` can return a result
  2425. // if called on a selectors message
  2426. bool hasPattern() const { return std::holds_alternative<Pattern>(body); }
  2427. bool bogus = false; // Set if a copy constructor fails
  2428. // A message body is either a matcher (selector list and variant list),
  2429. // or a single pattern
  2430. std::variant<Matcher, Pattern> body;
  2431. // Bindings for local variables
  2432. /* const */ LocalArray<Binding> bindings;
  2433. int32_t bindingsLen = 0;
  2434. const Binding* getLocalVariablesInternal() const;
  2435. const Expression* getSelectorsInternal() const;
  2436. const Variant* getVariantsInternal() const;
  2437. int32_t numSelectors() const {
  2438. const Matcher* matcher = std::get_if<Matcher>(&body);
  2439. return (matcher == nullptr ? 0 : matcher->numSelectors);
  2440. }
  2441. int32_t numVariants() const {
  2442. const Matcher* matcher = std::get_if<Matcher>(&body);
  2443. return (matcher == nullptr ? 0 : matcher->numVariants);
  2444. }
  2445. // Helper
  2446. void initBindings(const Binding*);
  2447. MFDataModel(const Builder& builder, UErrorCode&) noexcept;
  2448. }; // class MFDataModel
  2449. } // namespace message2
  2450. U_NAMESPACE_END
  2451. #endif // U_HIDE_DEPRECATED_API
  2452. #endif /* #if !UCONFIG_NO_MF2 */
  2453. #endif /* #if !UCONFIG_NO_FORMATTING */
  2454. #endif /* U_SHOW_CPLUSPLUS_API */
  2455. #endif // MESSAGEFORMAT_DATA_MODEL_H
  2456. // eof