builtin_fn_str.d.elv 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #elvdoc:fn <s <=s ==s !=s >s >=s {#str-cmp}
  2. #
  3. # ```elvish
  4. # <s $string... # less
  5. # <=s $string... # less or equal
  6. # ==s $string... # equal
  7. # !=s $string... # not equal
  8. # >s $string... # greater
  9. # >=s $string... # greater or equal
  10. # ```
  11. #
  12. # String comparisons. They behave similarly to their number counterparts when
  13. # given multiple arguments. Examples:
  14. #
  15. # ```elvish-transcript
  16. # ~> >s lorem ipsum
  17. # ▶ $true
  18. # ~> ==s 1 1.0
  19. # ▶ $false
  20. # ~> >s 8 12
  21. # ▶ $true
  22. # ```
  23. #elvdoc:fn wcswidth
  24. #
  25. # ```elvish
  26. # wcswidth $string
  27. # ```
  28. #
  29. # Output the width of `$string` when displayed on the terminal. Examples:
  30. #
  31. # ```elvish-transcript
  32. # ~> wcswidth a
  33. # ▶ 1
  34. # ~> wcswidth lorem
  35. # ▶ 5
  36. # ~> wcswidth 你好,世界
  37. # ▶ 10
  38. # ```
  39. #elvdoc:fn to-string
  40. #
  41. # ```elvish
  42. # to-string $value...
  43. # ```
  44. #
  45. # Convert arguments to string values.
  46. #
  47. # ```elvish-transcript
  48. # ~> to-string foo [a] [&k=v]
  49. # ▶ foo
  50. # ▶ '[a]'
  51. # ▶ '[&k=v]'
  52. # ```
  53. #elvdoc:fn base
  54. #
  55. # ```elvish
  56. # base $base $number...
  57. # ```
  58. #
  59. # Outputs a string for each `$number` written in `$base`. The `$base` must be
  60. # between 2 and 36, inclusive. Examples:
  61. #
  62. # ```elvish-transcript
  63. # ~> base 2 1 3 4 16 255
  64. # ▶ 1
  65. # ▶ 11
  66. # ▶ 100
  67. # ▶ 10000
  68. # ▶ 11111111
  69. # ~> base 16 1 3 4 16 255
  70. # ▶ 1
  71. # ▶ 3
  72. # ▶ 4
  73. # ▶ 10
  74. # ▶ ff
  75. # ```
  76. #elvdoc:fn eawk
  77. #
  78. # ```elvish
  79. # eawk $f $inputs?
  80. # ```
  81. #
  82. # For each [value input](#value-inputs), calls `$f` with the input followed by
  83. # all its fields. A [`break`](./builtin.html#break) command will cause `eawk`
  84. # to stop processing inputs. A [`continue`](./builtin.html#continue) command
  85. # will exit $f, but is ignored by `eawk`.
  86. #
  87. # It should behave the same as the following functions:
  88. #
  89. # ```elvish
  90. # fn eawk {|f @rest|
  91. # each {|line|
  92. # var @fields = (re:split '[ \t]+' (str:trim $line " \t"))
  93. # $f $line $@fields
  94. # } $@rest
  95. # }
  96. # ```
  97. #
  98. # This command allows you to write code very similar to `awk` scripts using
  99. # anonymous functions. Example:
  100. #
  101. # ```elvish-transcript
  102. # ~> echo " lorem ipsum\n1 2" | awk '{ print $1 }'
  103. # lorem
  104. # 1
  105. # ~> echo " lorem ipsum\n1 2" | eawk {|line a b| put $a }
  106. # ▶ lorem
  107. # ▶ 1
  108. # ```
  109. #
  110. # **Note**: Since Elvish allows variable names consisting solely of digits, you
  111. # can also do the following:
  112. #
  113. # ```elvish-transcript
  114. # ~> echo " lorem ipsum\n1 2" | eawk {|0 1 2| put $1 }
  115. # ▶ lorem
  116. # ▶ 1
  117. # ```