str.d.elv 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. #elvdoc:fn compare
  2. #
  3. # ```elvish
  4. # str:compare $a $b
  5. # ```
  6. #
  7. # Compares two strings and output an integer that will be 0 if a == b,
  8. # -1 if a < b, and +1 if a > b.
  9. #
  10. # ```elvish-transcript
  11. # ~> str:compare a a
  12. # ▶ 0
  13. # ~> str:compare a b
  14. # ▶ -1
  15. # ~> str:compare b a
  16. # ▶ 1
  17. # ```
  18. #elvdoc:fn contains
  19. #
  20. # ```elvish
  21. # str:contains $str $substr
  22. # ```
  23. #
  24. # Outputs whether `$str` contains `$substr` as a substring.
  25. #
  26. # ```elvish-transcript
  27. # ~> str:contains abcd x
  28. # ▶ $false
  29. # ~> str:contains abcd bc
  30. # ▶ $true
  31. # ```
  32. #elvdoc:fn contains-any
  33. #
  34. # ```elvish
  35. # str:contains-any $str $chars
  36. # ```
  37. #
  38. # Outputs whether `$str` contains any Unicode code points in `$chars`.
  39. #
  40. # ```elvish-transcript
  41. # ~> str:contains-any abcd x
  42. # ▶ $false
  43. # ~> str:contains-any abcd xby
  44. # ▶ $true
  45. # ```
  46. #elvdoc:fn count
  47. #
  48. # ```elvish
  49. # str:count $str $substr
  50. # ```
  51. #
  52. # Outputs the number of non-overlapping instances of `$substr` in `$s`.
  53. # If `$substr` is an empty string, output 1 + the number of Unicode code
  54. # points in `$s`.
  55. #
  56. # ```elvish-transcript
  57. # ~> str:count abcdefabcdef bc
  58. # ▶ 2
  59. # ~> str:count abcdef ''
  60. # ▶ 7
  61. # ```
  62. #elvdoc:fn equal-fold
  63. #
  64. # ```elvish
  65. # str:equal-fold $str1 $str2
  66. # ```
  67. #
  68. # Outputs if `$str1` and `$str2`, interpreted as UTF-8 strings, are equal
  69. # under Unicode case-folding.
  70. #
  71. # ```elvish-transcript
  72. # ~> str:equal-fold ABC abc
  73. # ▶ $true
  74. # ~> str:equal-fold abc ab
  75. # ▶ $false
  76. # ```
  77. #elvdoc:fn from-codepoints
  78. #
  79. # ```elvish
  80. # str:from-codepoints $number...
  81. # ```
  82. #
  83. # Outputs a string consisting of the given Unicode codepoints. Example:
  84. #
  85. # ```elvish-transcript
  86. # ~> str:from-codepoints 0x61
  87. # ▶ a
  88. # ~> str:from-codepoints 0x4f60 0x597d
  89. # ▶ 你好
  90. # ```
  91. #
  92. # @cf str:to-codepoints
  93. #elvdoc:fn from-utf8-bytes
  94. #
  95. # ```elvish
  96. # str:from-utf8-bytes $number...
  97. # ```
  98. #
  99. # Outputs a string consisting of the given Unicode bytes. Example:
  100. #
  101. # ```elvish-transcript
  102. # ~> str:from-utf8-bytes 0x61
  103. # ▶ a
  104. # ~> str:from-utf8-bytes 0xe4 0xbd 0xa0 0xe5 0xa5 0xbd
  105. # ▶ 你好
  106. # ```
  107. #
  108. # @cf str:to-utf8-bytes
  109. #elvdoc:fn has-prefix
  110. #
  111. # ```elvish
  112. # str:has-prefix $str $prefix
  113. # ```
  114. #
  115. # Outputs if `$str` begins with `$prefix`.
  116. #
  117. # ```elvish-transcript
  118. # ~> str:has-prefix abc ab
  119. # ▶ $true
  120. # ~> str:has-prefix abc bc
  121. # ▶ $false
  122. # ```
  123. #elvdoc:fn has-suffix
  124. #
  125. # ```elvish
  126. # str:has-suffix $str $suffix
  127. # ```
  128. #
  129. # Outputs if `$str` ends with `$suffix`.
  130. #
  131. # ```elvish-transcript
  132. # ~> str:has-suffix abc ab
  133. # ▶ $false
  134. # ~> str:has-suffix abc bc
  135. # ▶ $true
  136. # ```
  137. #elvdoc:fn index
  138. #
  139. # ```elvish
  140. # str:index $str $substr
  141. # ```
  142. #
  143. # Outputs the index of the first instance of `$substr` in `$str`, or -1
  144. # if `$substr` is not present in `$str`.
  145. #
  146. # ```elvish-transcript
  147. # ~> str:index abcd cd
  148. # ▶ 2
  149. # ~> str:index abcd xyz
  150. # ▶ -1
  151. # ```
  152. #elvdoc:fn index-any
  153. #
  154. # ```elvish
  155. # str:index-any $str $chars
  156. # ```
  157. #
  158. # Outputs the index of the first instance of any Unicode code point
  159. # from `$chars` in `$str`, or -1 if no Unicode code point from `$chars` is
  160. # present in `$str`.
  161. #
  162. # ```elvish-transcript
  163. # ~> str:index-any "chicken" "aeiouy"
  164. # ▶ 2
  165. # ~> str:index-any l33t aeiouy
  166. # ▶ -1
  167. # ```
  168. #elvdoc:fn join
  169. #
  170. # ```elvish
  171. # str:join $sep $input-list?
  172. # ```
  173. #
  174. # Joins inputs with `$sep`. Examples:
  175. #
  176. # ```elvish-transcript
  177. # ~> put lorem ipsum | str:join ,
  178. # ▶ lorem,ipsum
  179. # ~> str:join , [lorem ipsum]
  180. # ▶ lorem,ipsum
  181. # ~> str:join '' [lorem ipsum]
  182. # ▶ loremipsum
  183. # ~> str:join '...' [lorem ipsum]
  184. # ▶ lorem...ipsum
  185. # ```
  186. #
  187. # Etymology: Various languages,
  188. # [Python](https://docs.python.org/3.6/library/stdtypes.html#str.join).
  189. #
  190. # @cf str:split
  191. #elvdoc:fn last-index
  192. #
  193. # ```elvish
  194. # str:last-index $str $substr
  195. # ```
  196. #
  197. # Outputs the index of the last instance of `$substr` in `$str`,
  198. # or -1 if `$substr` is not present in `$str`.
  199. #
  200. # ```elvish-transcript
  201. # ~> str:last-index "elven speak elvish" elv
  202. # ▶ 12
  203. # ~> str:last-index "elven speak elvish" romulan
  204. # ▶ -1
  205. # ```
  206. #elvdoc:fn replace
  207. #
  208. # ```elvish
  209. # str:replace &max=-1 $old $repl $source
  210. # ```
  211. #
  212. # Replaces all occurrences of `$old` with `$repl` in `$source`. If `$max` is
  213. # non-negative, it determines the max number of substitutions.
  214. #
  215. # **Note**: This command does not support searching by regular expressions, `$old`
  216. # is always interpreted as a plain string. Use [re:replace](re.html#re:replace) if
  217. # you need to search by regex.
  218. #elvdoc:fn split
  219. #
  220. # ```elvish
  221. # str:split &max=-1 $sep $string
  222. # ```
  223. #
  224. # Splits `$string` by `$sep`. If `$sep` is an empty string, split it into
  225. # codepoints.
  226. #
  227. # If the `&max` option is non-negative, stops after producing the maximum
  228. # number of results.
  229. #
  230. # ```elvish-transcript
  231. # ~> str:split , lorem,ipsum
  232. # ▶ lorem
  233. # ▶ ipsum
  234. # ~> str:split '' 你好
  235. # ▶ 你
  236. # ▶ 好
  237. # ~> str:split &max=2 ' ' 'a b c d'
  238. # ▶ a
  239. # ▶ 'b c d'
  240. # ```
  241. #
  242. # **Note**: This command does not support splitting by regular expressions,
  243. # `$sep` is always interpreted as a plain string. Use [re:split](re.html#re:split)
  244. # if you need to split by regex.
  245. #
  246. # Etymology: Various languages, in particular
  247. # [Python](https://docs.python.org/3.6/library/stdtypes.html#str.split).
  248. #
  249. # @cf str:join
  250. #elvdoc:fn title
  251. #
  252. # ```elvish
  253. # str:title $str
  254. # ```
  255. #
  256. # Outputs `$str` with all Unicode letters that begin words mapped to their
  257. # Unicode title case.
  258. #
  259. # ```elvish-transcript
  260. # ~> str:title "her royal highness"
  261. # ▶ Her Royal Highness
  262. # ```
  263. #elvdoc:fn to-codepoints
  264. #
  265. # ```elvish
  266. # str:to-codepoints $string
  267. # ```
  268. #
  269. # Outputs value of each codepoint in `$string`, in hexadecimal. Examples:
  270. #
  271. # ```elvish-transcript
  272. # ~> str:to-codepoints a
  273. # ▶ 0x61
  274. # ~> str:to-codepoints 你好
  275. # ▶ 0x4f60
  276. # ▶ 0x597d
  277. # ```
  278. #
  279. # The output format is subject to change.
  280. #
  281. # @cf str:from-codepoints
  282. #elvdoc:fn to-lower
  283. #
  284. # ```elvish
  285. # str:to-lower $str
  286. # ```
  287. #
  288. # Outputs `$str` with all Unicode letters mapped to their lower-case
  289. # equivalent.
  290. #
  291. # ```elvish-transcript
  292. # ~> str:to-lower 'ABC!123'
  293. # ▶ abc!123
  294. # ```
  295. #elvdoc:fn to-utf8-bytes
  296. #
  297. # ```elvish
  298. # str:to-utf8-bytes $string
  299. # ```
  300. #
  301. # Outputs value of each byte in `$string`, in hexadecimal. Examples:
  302. #
  303. # ```elvish-transcript
  304. # ~> str:to-utf8-bytes a
  305. # ▶ 0x61
  306. # ~> str:to-utf8-bytes 你好
  307. # ▶ 0xe4
  308. # ▶ 0xbd
  309. # ▶ 0xa0
  310. # ▶ 0xe5
  311. # ▶ 0xa5
  312. # ▶ 0xbd
  313. # ```
  314. #
  315. # The output format is subject to change.
  316. #
  317. # @cf str:from-utf8-bytes
  318. #elvdoc:fn to-title
  319. #
  320. # ```elvish
  321. # str:to-title $str
  322. # ```
  323. #
  324. # Outputs `$str` with all Unicode letters mapped to their Unicode title case.
  325. #
  326. # ```elvish-transcript
  327. # ~> str:to-title "her royal highness"
  328. # ▶ HER ROYAL HIGHNESS
  329. # ~> str:to-title "хлеб"
  330. # ▶ ХЛЕБ
  331. # ```
  332. #elvdoc:fn to-upper
  333. #
  334. # ```elvish
  335. # str:to-upper
  336. # ```
  337. #
  338. # Outputs `$str` with all Unicode letters mapped to their upper-case
  339. # equivalent.
  340. #
  341. # ```elvish-transcript
  342. # ~> str:to-upper 'abc!123'
  343. # ▶ ABC!123
  344. # ```
  345. #elvdoc:fn trim
  346. #
  347. # ```elvish
  348. # str:trim $str $cutset
  349. # ```
  350. #
  351. # Outputs `$str` with all leading and trailing Unicode code points contained
  352. # in `$cutset` removed.
  353. #
  354. # ```elvish-transcript
  355. # ~> str:trim "¡¡¡Hello, Elven!!!" "!¡"
  356. # ▶ 'Hello, Elven'
  357. # ```
  358. #elvdoc:fn trim-left
  359. #
  360. # ```elvish
  361. # str:trim-left $str $cutset
  362. # ```
  363. #
  364. # Outputs `$str` with all leading Unicode code points contained in `$cutset`
  365. # removed. To remove a prefix string use [`str:trim-prefix`](#str:trim-prefix).
  366. #
  367. # ```elvish-transcript
  368. # ~> str:trim-left "¡¡¡Hello, Elven!!!" "!¡"
  369. # ▶ 'Hello, Elven!!!'
  370. # ```
  371. #elvdoc:fn trim-prefix
  372. #
  373. # ```elvish
  374. # str:trim-prefix $str $prefix
  375. # ```
  376. #
  377. # Outputs `$str` minus the leading `$prefix` string. If `$str` doesn't begin
  378. # with `$prefix`, `$str` is output unchanged.
  379. #
  380. # ```elvish-transcript
  381. # ~> str:trim-prefix "¡¡¡Hello, Elven!!!" "¡¡¡Hello, "
  382. # ▶ Elven!!!
  383. # ~> str:trim-prefix "¡¡¡Hello, Elven!!!" "¡¡¡Hola, "
  384. # ▶ '¡¡¡Hello, Elven!!!'
  385. # ```
  386. #elvdoc:fn trim-right
  387. #
  388. # ```elvish
  389. # str:trim-right $str $cutset
  390. # ```
  391. #
  392. # Outputs `$str` with all leading Unicode code points contained in `$cutset`
  393. # removed. To remove a suffix string use [`str:trim-suffix`](#str:trim-suffix).
  394. #
  395. # ```elvish-transcript
  396. # ~> str:trim-right "¡¡¡Hello, Elven!!!" "!¡"
  397. # ▶ '¡¡¡Hello, Elven'
  398. # ```
  399. #elvdoc:fn trim-space
  400. #
  401. # ```elvish
  402. # str:trim-space $str
  403. # ```
  404. #
  405. # Outputs `$str` with all leading and trailing white space removed as defined
  406. # by Unicode.
  407. #
  408. # ```elvish-transcript
  409. # ~> str:trim-space " \t\n Hello, Elven \n\t\r\n"
  410. # ▶ 'Hello, Elven'
  411. # ```
  412. #elvdoc:fn trim-suffix
  413. #
  414. # ```elvish
  415. # str:trim-suffix $str $suffix
  416. # ```
  417. #
  418. # Outputs `$str` minus the trailing `$suffix` string. If `$str` doesn't end
  419. # with `$suffix`, `$str` is output unchanged.
  420. #
  421. # ```elvish-transcript
  422. # ~> str:trim-suffix "¡¡¡Hello, Elven!!!" ", Elven!!!"
  423. # ▶ ¡¡¡Hello
  424. # ~> str:trim-suffix "¡¡¡Hello, Elven!!!" ", Klingons!!!"
  425. # ▶ '¡¡¡Hello, Elven!!!'
  426. # ```