string.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. string
  2. ------
  3. String operations.
  4. Synopsis
  5. ^^^^^^^^
  6. .. parsed-literal::
  7. `Search and Replace`_
  8. string(`FIND`_ <string> <substring> <out-var> [...])
  9. string(`REPLACE`_ <match-string> <replace-string> <out-var> <input>...)
  10. string(`REGEX MATCH`_ <match-regex> <out-var> <input>...)
  11. string(`REGEX MATCHALL`_ <match-regex> <out-var> <input>...)
  12. string(`REGEX REPLACE`_ <match-regex> <replace-expr> <out-var> <input>...)
  13. `Manipulation`_
  14. string(`APPEND`_ <string-var> [<input>...])
  15. string(`PREPEND`_ <string-var> [<input>...])
  16. string(`CONCAT`_ <out-var> [<input>...])
  17. string(`JOIN`_ <glue> <out-var> [<input>...])
  18. string(`TOLOWER`_ <string> <out-var>)
  19. string(`TOUPPER`_ <string> <out-var>)
  20. string(`LENGTH`_ <string> <out-var>)
  21. string(`SUBSTRING`_ <string> <begin> <length> <out-var>)
  22. string(`STRIP`_ <string> <out-var>)
  23. string(`GENEX_STRIP`_ <string> <out-var>)
  24. string(`REPEAT`_ <string> <count> <out-var>)
  25. string(`REGEX QUOTE`_ <out-var> <input>...)
  26. `Comparison`_
  27. string(`COMPARE`_ <op> <string1> <string2> <out-var>)
  28. `Hashing`_
  29. string(`\<HASH\>`_ <out-var> <input>)
  30. `Generation`_
  31. string(`ASCII`_ <number>... <out-var>)
  32. string(`HEX`_ <string> <out-var>)
  33. string(`CONFIGURE`_ <string> <out-var> [...])
  34. string(`MAKE_C_IDENTIFIER`_ <string> <out-var>)
  35. string(`RANDOM`_ [<option>...] <out-var>)
  36. string(`TIMESTAMP`_ <out-var> [<format string>] [UTC])
  37. string(`UUID`_ <out-var> ...)
  38. `JSON`_
  39. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  40. {`GET <JSON-GET_>`__ | `GET_RAW <JSON-GET-RAW_>`__ | `TYPE <JSON-TYPE_>`__ | `LENGTH <JSON-LENGTH_>`__ | `REMOVE <JSON-REMOVE_>`__}
  41. <json-string> <member|index> [<member|index> ...])
  42. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  43. `MEMBER <JSON-MEMBER_>`__ <json-string>
  44. [<member|index> ...] <index>)
  45. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  46. `SET <JSON-SET_>`__ <json-string>
  47. <member|index> [<member|index> ...] <value>)
  48. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  49. `EQUAL <JSON-EQUAL_>`__ <json-string1> <json-string2>)
  50. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  51. `STRING_ENCODE <STRING-ENCODE_>`__ <string>)
  52. Search and Replace
  53. ^^^^^^^^^^^^^^^^^^
  54. Search and Replace With Plain Strings
  55. """""""""""""""""""""""""""""""""""""
  56. .. signature::
  57. string(FIND <string> <substring> <output_variable> [REVERSE])
  58. Return the position where the given ``<substring>`` was found in
  59. the supplied ``<string>``. If the ``REVERSE`` flag was used, the command
  60. will search for the position of the last occurrence of the specified
  61. ``<substring>``. If the ``<substring>`` is not found, a position of -1 is
  62. returned.
  63. The ``string(FIND)`` subcommand treats all strings as ASCII-only characters.
  64. The index stored in ``<output_variable>`` will also be counted in bytes,
  65. so strings containing multi-byte characters may lead to unexpected results.
  66. .. signature::
  67. string(REPLACE <match_string>
  68. <replace_string> <output_variable>
  69. <input> [<input>...])
  70. Replace all occurrences of ``<match_string>`` in the ``<input>``
  71. with ``<replace_string>`` and store the result in the ``<output_variable>``.
  72. Search and Replace With Regular Expressions
  73. """""""""""""""""""""""""""""""""""""""""""
  74. .. signature::
  75. string(REGEX MATCH <regular_expression>
  76. <output_variable> <input> [<input>...])
  77. Match the ``<regular_expression>`` once and store the match in the
  78. ``<output_variable>``.
  79. All ``<input>`` arguments are concatenated before matching.
  80. Regular expressions are specified in the subsection just below.
  81. .. signature::
  82. string(REGEX MATCHALL <regular_expression>
  83. <output_variable> <input> [<input>...])
  84. Match the ``<regular_expression>`` as many times as possible and store the
  85. matches in the ``<output_variable>`` as a list.
  86. All ``<input>`` arguments are concatenated before matching.
  87. .. signature::
  88. string(REGEX REPLACE <regular_expression>
  89. <replacement_expression> <output_variable>
  90. <input> [<input>...])
  91. Match the ``<regular_expression>`` as many times as possible and substitute
  92. the ``<replacement_expression>`` for the match in the output.
  93. All ``<input>`` arguments are concatenated before matching.
  94. The ``<replacement_expression>`` may refer to parenthesis-delimited
  95. subexpressions of the match using ``\1``, ``\2``, ..., ``\9``. Note that
  96. two backslashes (``\\1``) are required in CMake code to get a backslash
  97. through argument parsing.
  98. .. versionchanged:: 4.1
  99. The ``^`` anchor now matches only at the beginning of the input
  100. string instead of the beginning of each repeated search.
  101. See policy :policy:`CMP0186`.
  102. Zero-length matches are allowed in ``MATCHALL`` and ``REPLACE``.
  103. Previously, they triggered an error.
  104. The replacement expression may contain references to subexpressions that
  105. didn't match anything. Previously, such references triggered an error.
  106. .. _`Regex Specification`:
  107. Regex Specification
  108. """""""""""""""""""
  109. The following characters have special meaning in regular expressions:
  110. ``^``
  111. Matches at beginning of input
  112. ``$``
  113. Matches at end of input
  114. ``.``
  115. Matches any single character
  116. ``\<char>``
  117. Matches the single character specified by ``<char>``. Use this to
  118. match special regex characters, e.g. ``\.`` for a literal ``.``
  119. or ``\\`` for a literal backslash ``\``. Escaping a non-special
  120. character is unnecessary but allowed, e.g. ``\a`` matches ``a``.
  121. ``[ ]``
  122. Matches any character(s) inside the brackets.
  123. To match a literal ``]``, make it the first character, e.g., ``[]ab]``.
  124. ``[^ ]``
  125. Matches any character(s) not inside the brackets.
  126. To not match a literal ``]``, make it the first character, e.g., ``[^]ab]``.
  127. ``-``
  128. Inside brackets, specifies an inclusive range between characters on
  129. either side, e.g., ``[a-f]`` is ``[abcdef]``.
  130. To match a literal ``-`` using brackets, make it the first or the last
  131. character, e.g., ``[+*/-]`` matches basic mathematical operators.
  132. ``*``
  133. Matches preceding pattern zero or more times
  134. ``+``
  135. Matches preceding pattern one or more times
  136. ``?``
  137. Matches preceding pattern zero or once only
  138. ``|``
  139. Matches a pattern on either side of the ``|``
  140. ``()``
  141. Saves a matched subexpression, which can be referenced
  142. in the ``REGEX REPLACE`` operation.
  143. .. versionadded:: 3.9
  144. All regular expression-related commands, including e.g.
  145. :command:`if(MATCHES)`, save subgroup matches in the variables
  146. :variable:`CMAKE_MATCH_<n>` for ``<n>`` 0..9.
  147. .. noqa: spellcheck off
  148. ``*``, ``+`` and ``?`` have higher precedence than concatenation. ``|``
  149. has lower precedence than concatenation. This means that the regular
  150. expression ``^ab+d$`` matches ``abbd`` but not ``ababd``, and the regular
  151. expression ``^(ab|cd)$`` matches ``ab`` but not ``abd``.
  152. .. noqa: spellcheck on
  153. CMake language :ref:`Escape Sequences` such as ``\t``, ``\r``, ``\n``,
  154. and ``\\`` may be used to construct literal tabs, carriage returns,
  155. newlines, and backslashes (respectively) to pass in a regex. For example:
  156. * The quoted argument ``"[ \t\r\n]"`` specifies a regex that matches
  157. any single whitespace character.
  158. * The quoted argument ``"[/\\]"`` specifies a regex that matches
  159. a single forward slash ``/`` or backslash ``\``.
  160. * The quoted argument ``"[A-Za-z0-9_]"`` specifies a regex that matches
  161. any single "word" character in the C locale.
  162. * The quoted argument ``"\\(\\a\\+b\\)"`` specifies a regex that matches
  163. the exact string ``(a+b)``. Each ``\\`` is parsed in a quoted argument
  164. as just ``\``, so the regex itself is actually ``\(\a\+\b\)``. This
  165. can alternatively be specified in a :ref:`bracket argument` without
  166. having to escape the backslashes, e.g. ``[[\(\a\+\b\)]]``.
  167. Manipulation
  168. ^^^^^^^^^^^^
  169. .. signature::
  170. string(APPEND <string_variable> [<input>...])
  171. .. versionadded:: 3.4
  172. Append all the ``<input>`` arguments to the string.
  173. .. signature::
  174. string(PREPEND <string_variable> [<input>...])
  175. .. versionadded:: 3.10
  176. Prepend all the ``<input>`` arguments to the string.
  177. .. signature::
  178. string(CONCAT <output_variable> [<input>...])
  179. Concatenate all the ``<input>`` arguments together and store
  180. the result in the named ``<output_variable>``.
  181. .. signature::
  182. string(JOIN <glue> <output_variable> [<input>...])
  183. .. versionadded:: 3.12
  184. Join all the ``<input>`` arguments together using the ``<glue>``
  185. string and store the result in the named ``<output_variable>``.
  186. To join a list's elements, prefer to use the ``JOIN`` operator
  187. from the :command:`list` command. This allows for the elements to have
  188. special characters like ``;`` in them.
  189. .. signature::
  190. string(TOLOWER <string> <output_variable>)
  191. Convert ``<string>`` to lower characters.
  192. .. signature::
  193. string(TOUPPER <string> <output_variable>)
  194. Convert ``<string>`` to upper characters.
  195. .. signature::
  196. string(LENGTH <string> <output_variable>)
  197. Store in an ``<output_variable>`` a given string's length in bytes.
  198. Note that this means if ``<string>`` contains multi-byte characters,
  199. the result stored in ``<output_variable>`` will *not* be
  200. the number of characters.
  201. .. signature::
  202. string(SUBSTRING <string> <begin> <length> <output_variable>)
  203. Store in an ``<output_variable>`` a substring of a given ``<string>``. If
  204. ``<length>`` is ``-1`` the remainder of the string starting at ``<begin>``
  205. will be returned.
  206. .. versionchanged:: 3.2
  207. If ``<string>`` is shorter than ``<length>``
  208. then the end of the string is used instead.
  209. Previous versions of CMake reported an error in this case.
  210. Both ``<begin>`` and ``<length>`` are counted in bytes, so care must
  211. be exercised if ``<string>`` could contain multi-byte characters.
  212. .. signature::
  213. string(STRIP <string> <output_variable>)
  214. Store in an ``<output_variable>`` a substring of a given ``<string>``
  215. with leading and trailing spaces removed.
  216. .. signature::
  217. string(GENEX_STRIP <string> <output_variable>)
  218. .. versionadded:: 3.1
  219. Strip any :manual:`generator expressions <cmake-generator-expressions(7)>`
  220. from the input ``<string>`` and store the result
  221. in the ``<output_variable>``.
  222. .. signature::
  223. string(REPEAT <string> <count> <output_variable>)
  224. .. versionadded:: 3.15
  225. Produce the output string as the input ``<string>``
  226. repeated ``<count>`` times.
  227. .. signature::
  228. string(REGEX QUOTE <out-var> <input>...)
  229. .. versionadded:: 4.2
  230. Store in an ``<out-var>`` a regular expression matching the ``<input>``.
  231. All characters that have special meaning in a regular expression are
  232. escaped, such that the output string can be used as part of a regular
  233. expression to match the input literally.
  234. Comparison
  235. ^^^^^^^^^^
  236. .. _COMPARE:
  237. .. signature::
  238. string(COMPARE LESS <string1> <string2> <output_variable>)
  239. string(COMPARE GREATER <string1> <string2> <output_variable>)
  240. string(COMPARE EQUAL <string1> <string2> <output_variable>)
  241. string(COMPARE NOTEQUAL <string1> <string2> <output_variable>)
  242. string(COMPARE LESS_EQUAL <string1> <string2> <output_variable>)
  243. string(COMPARE GREATER_EQUAL <string1> <string2> <output_variable>)
  244. Compare the strings and store true or false in the ``<output_variable>``.
  245. .. versionadded:: 3.7
  246. Added the ``LESS_EQUAL`` and ``GREATER_EQUAL`` options.
  247. .. _`Supported Hash Algorithms`:
  248. Hashing
  249. ^^^^^^^
  250. .. signature::
  251. string(<HASH> <output_variable> <input>)
  252. :target: <HASH>
  253. Compute a cryptographic hash of the ``<input>`` string.
  254. The supported ``<HASH>`` algorithm names are:
  255. ``MD5``
  256. Message-Digest Algorithm 5, RFC 1321.
  257. ``SHA1``
  258. US Secure Hash Algorithm 1, RFC 3174.
  259. ``SHA224``
  260. US Secure Hash Algorithms, RFC 4634.
  261. ``SHA256``
  262. US Secure Hash Algorithms, RFC 4634.
  263. ``SHA384``
  264. US Secure Hash Algorithms, RFC 4634.
  265. ``SHA512``
  266. US Secure Hash Algorithms, RFC 4634.
  267. ``SHA3_224``
  268. Keccak SHA-3.
  269. ``SHA3_256``
  270. Keccak SHA-3.
  271. ``SHA3_384``
  272. Keccak SHA-3.
  273. ``SHA3_512``
  274. Keccak SHA-3.
  275. .. versionadded:: 3.8
  276. Added the ``SHA3_*`` hash algorithms.
  277. Generation
  278. ^^^^^^^^^^
  279. .. signature::
  280. string(ASCII <number> [<number> ...] <output_variable>)
  281. Convert all numbers into corresponding ASCII characters.
  282. .. signature::
  283. string(HEX <string> <output_variable>)
  284. .. versionadded:: 3.18
  285. Convert each byte in the input ``<string>`` to its hexadecimal representation
  286. and store the concatenated hex digits in the ``<output_variable>``.
  287. Letters in the output (``a`` through ``f``) are in lowercase.
  288. .. signature::
  289. string(CONFIGURE <string> <output_variable>
  290. [@ONLY] [ESCAPE_QUOTES])
  291. Transform a ``<string>`` like :command:`configure_file` transforms a file.
  292. .. signature::
  293. string(MAKE_C_IDENTIFIER <string> <output_variable>)
  294. Convert each non-alphanumeric character in the input ``<string>`` to an
  295. underscore and store the result in the ``<output_variable>``. If the first
  296. character of the ``<string>`` is a digit, an underscore will also be
  297. prepended to the result.
  298. .. signature::
  299. string(RANDOM [LENGTH <length>] [ALPHABET <alphabet>]
  300. [RANDOM_SEED <seed>] <output_variable>)
  301. Return a random string of given ``<length>`` consisting of
  302. characters from the given ``<alphabet>``. Default length is 5 characters
  303. and default alphabet is all numbers and upper and lower case letters.
  304. If an integer ``RANDOM_SEED`` is given, its value will be used to seed the
  305. random number generator.
  306. .. signature::
  307. string(TIMESTAMP <output_variable> [<format_string>] [UTC])
  308. Write a string representation of the current date
  309. and/or time to the ``<output_variable>``.
  310. If the command is unable to obtain a timestamp, the ``<output_variable>``
  311. will be set to the empty string ``""``.
  312. The optional ``UTC`` flag requests the current date/time representation to
  313. be in Coordinated Universal Time (UTC) rather than local time.
  314. The optional ``<format_string>`` may contain the following format
  315. specifiers:
  316. ``%%``
  317. .. versionadded:: 3.8
  318. A literal percent sign (%).
  319. ``%d``
  320. The day of the current month (01-31).
  321. ``%H``
  322. The hour on a 24-hour clock (00-23).
  323. ``%I``
  324. The hour on a 12-hour clock (01-12).
  325. ``%j``
  326. The day of the current year (001-366).
  327. ``%m``
  328. The month of the current year (01-12).
  329. ``%b``
  330. .. versionadded:: 3.7
  331. Abbreviated month name (e.g. Oct).
  332. ``%B``
  333. .. versionadded:: 3.10
  334. Full month name (e.g. October).
  335. ``%M``
  336. The minute of the current hour (00-59).
  337. ``%s``
  338. .. versionadded:: 3.6
  339. Seconds since midnight (UTC) 1-Jan-1970 (UNIX time).
  340. ``%S``
  341. The second of the current minute. 60 represents a leap second. (00-60)
  342. ``%f``
  343. .. versionadded:: 3.23
  344. The microsecond of the current second (000000-999999).
  345. ``%U``
  346. The week number of the current year (00-53).
  347. ``%V``
  348. .. versionadded:: 3.22
  349. The ISO 8601 week number of the current year (01-53).
  350. ``%w``
  351. The day of the current week. 0 is Sunday. (0-6)
  352. ``%a``
  353. .. versionadded:: 3.7
  354. Abbreviated weekday name (e.g. Fri).
  355. ``%A``
  356. .. versionadded:: 3.10
  357. Full weekday name (e.g. Friday).
  358. ``%y``
  359. The last two digits of the current year (00-99).
  360. ``%Y``
  361. The current year.
  362. ``%z``
  363. .. versionadded:: 3.26
  364. The offset of the time zone from UTC, in hours and minutes,
  365. with format ``+hhmm`` or ``-hhmm``.
  366. ``%Z``
  367. .. versionadded:: 3.26
  368. The time zone name.
  369. Unknown format specifiers will be ignored and copied to the output
  370. as-is.
  371. If no explicit ``<format_string>`` is given, it will default to:
  372. * ``%Y-%m-%dT%H:%M:%S`` for local time.
  373. * ``%Y-%m-%dT%H:%M:%SZ`` for UTC.
  374. .. versionadded:: 3.8
  375. If the ``SOURCE_DATE_EPOCH`` environment variable is set,
  376. its value will be used instead of the current time.
  377. See https://reproducible-builds.org/specs/source-date-epoch/ for details.
  378. .. signature::
  379. string(UUID <output_variable> NAMESPACE <namespace> NAME <name>
  380. TYPE <MD5|SHA1> [UPPER])
  381. .. versionadded:: 3.1
  382. Create a universally unique identifier (aka GUID) as per RFC4122
  383. based on the hash of the combined values of ``<namespace>``
  384. (which itself has to be a valid UUID) and ``<name>``.
  385. The hash algorithm can be either ``MD5`` (Version 3 UUID) or
  386. ``SHA1`` (Version 5 UUID).
  387. A UUID has the format ``xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx``
  388. where each ``x`` represents a lower case hexadecimal character.
  389. Where required, an uppercase representation can be requested
  390. with the optional ``UPPER`` flag.
  391. .. _JSON:
  392. JSON
  393. ^^^^
  394. .. versionadded:: 3.19
  395. Functionality for querying a JSON string.
  396. .. note::
  397. In each of the following JSON-related subcommands, if the optional
  398. ``ERROR_VARIABLE`` argument is given, errors will be reported in
  399. ``<error-variable>`` and the ``<out-var>`` will be set to
  400. ``<member|index>-[<member|index>...]-NOTFOUND`` with the path elements
  401. up to the point where the error occurred, or just ``NOTFOUND`` if there
  402. is no relevant path. If an error occurs but the ``ERROR_VARIABLE``
  403. option is not present, a fatal error message is generated. If no error
  404. occurs, the ``<error-variable>`` will be set to ``NOTFOUND``.
  405. In the following subcommands, the ``<json-string>`` argument should
  406. be written as a :ref:`Quoted Argument` to ensure the entire JSON
  407. string is passed as a single argument even if it contains semicolons.
  408. .. signature::
  409. string(JSON <out-var> [ERROR_VARIABLE <error-variable>]
  410. GET <json-string> <member|index> [<member|index> ...])
  411. :target: JSON-GET
  412. Get an element from ``<json-string>`` at the location given
  413. by the list of ``<member|index>`` arguments.
  414. Array and object elements will be returned as a JSON string.
  415. Boolean elements will be returned as ``ON`` or ``OFF``.
  416. Null elements will be returned as an empty string.
  417. Number and string types will be returned as strings.
  418. .. signature::
  419. string(JSON <out-var> [ERROR_VARIABLE <error-variable>]
  420. GET_RAW <json-string> <member|index> [<member|index> ...])
  421. :target: JSON-GET-RAW
  422. Get an element from ``<json-string>`` at the location given
  423. by the list of ``<member|index>`` arguments. Similar to
  424. `GET <JSON-GET_>`__, but does not convert number, string,
  425. boolean, or null elements.
  426. .. signature::
  427. string(JSON <out-var> [ERROR_VARIABLE <error-variable>]
  428. TYPE <json-string> <member|index> [<member|index> ...])
  429. :target: JSON-TYPE
  430. Get the type of an element in ``<json-string>`` at the location
  431. given by the list of ``<member|index>`` arguments. The ``<out-var>``
  432. will be set to one of ``NULL``, ``NUMBER``, ``STRING``, ``BOOLEAN``,
  433. ``ARRAY``, or ``OBJECT``.
  434. .. signature::
  435. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  436. MEMBER <json-string>
  437. [<member|index> ...] <index>)
  438. :target: JSON-MEMBER
  439. Get the name of the ``<index>``-th member in ``<json-string>``
  440. at the location given by the list of ``<member|index>`` arguments.
  441. Requires an element of object type.
  442. .. signature::
  443. string(JSON <out-var> [ERROR_VARIABLE <error-variable>]
  444. LENGTH <json-string> [<member|index> ...])
  445. :target: JSON-LENGTH
  446. Get the length of an element in ``<json-string>`` at the location
  447. given by the list of ``<member|index>`` arguments.
  448. Requires an element of array or object type.
  449. .. signature::
  450. string(JSON <out-var> [ERROR_VARIABLE <error-variable>]
  451. REMOVE <json-string> <member|index> [<member|index> ...])
  452. :target: JSON-REMOVE
  453. Remove an element from ``<json-string>`` at the location
  454. given by the list of ``<member|index>`` arguments. The JSON string
  455. without the removed element will be stored in ``<out-var>``.
  456. .. signature::
  457. string(JSON <out-var> [ERROR_VARIABLE <error-variable>]
  458. SET <json-string> <member|index> [<member|index> ...] <value>)
  459. :target: JSON-SET
  460. Set an element in ``<json-string>`` at the location
  461. given by the list of ``<member|index>`` arguments to ``<value>``.
  462. The contents of ``<value>`` should be valid JSON.
  463. If ``<json-string>`` is an array, ``<value>`` can be appended to the end of
  464. the array by using a number greater or equal to the array length as the
  465. ``<member|index>`` argument.
  466. .. signature::
  467. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  468. EQUAL <json-string1> <json-string2>)
  469. :target: JSON-EQUAL
  470. Compare the two JSON objects given by ``<json-string1>``
  471. and ``<json-string2>`` for equality. The contents of ``<json-string1>``
  472. and ``<json-string2>`` should be valid JSON. The ``<out-var>``
  473. will be set to a true value if the JSON objects are considered equal,
  474. or a false value otherwise.
  475. .. signature::
  476. string(JSON <out-var> [ERROR_VARIABLE <error-var>]
  477. STRING_ENCODE <string>)
  478. :target: STRING-ENCODE
  479. Turn a raw string into a JSON string surrounded by quotes. Special characters
  480. will be properly escaped inside the JSON string.