aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMartin Dørum <dorum@noisolation.com>2023-06-19 16:55:16 +0200
committerXavier Claessens <xclaesse@gmail.com>2023-06-20 08:28:47 -0400
commite869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9 (patch)
tree88f235010db650cef6d475225acf7e7d157c6c2c /docs
parent8c766f5b5bd33c93deabff41e2152d7f7e368492 (diff)
downloadmeson-e869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9.zip
meson-e869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9.tar.gz
meson-e869a09bc2e0fbd988fdc19014b8b0ad7e4b97c9.tar.bz2
add str.splitlines method
The new splitlines method on str is intended to replace usage of fs.read('whatever').strip().split('\n'). The problem with the .strip().split() approach is that it doesn't have a way to represent empty lists (an empty string becomes a list with one empty string, not an empty list), and it doesn't handle Windows-style line endings.
Diffstat (limited to 'docs')
-rw-r--r--docs/markdown/snippets/add_str_splitlines_method.md3
-rw-r--r--docs/yaml/elementary/str.yml22
2 files changed, 25 insertions, 0 deletions
diff --git a/docs/markdown/snippets/add_str_splitlines_method.md b/docs/markdown/snippets/add_str_splitlines_method.md
new file mode 100644
index 0000000..6787f17
--- /dev/null
+++ b/docs/markdown/snippets/add_str_splitlines_method.md
@@ -0,0 +1,3 @@
+## Added str.splitlines method
+
+[[str.splitlines]] can now be used to split a string into an array of lines.
diff --git a/docs/yaml/elementary/str.yml b/docs/yaml/elementary/str.yml
index 00587cb..dca6382 100644
--- a/docs/yaml/elementary/str.yml
+++ b/docs/yaml/elementary/str.yml
@@ -204,6 +204,28 @@ methods:
type: str
description: Specifies the character / substring where to split the string.
+- name: splitlines
+ returns: list[str]
+ since: 1.2.0
+ description: |
+ Splits the string into an array of lines.
+ Unlike .split('\n'), the empty string produced an empty array,
+ and if the string ends in a newline, splitlines() doesn't split
+ on that last newline.
+ '\n', '\r' and '\r\n' are all considered newlines.
+
+ example: |
+ ```meson
+ output = 'hello\nworld\n'.splitlines()
+ # Output value is ['hello', 'world']
+ output = ''.splitlines()
+ # Output value is []
+ fs = import('fs')
+ paths = fs.read('my_paths.list').splitlines()
+ # paths is now the paths listed in 'my_paths.list', or an empty list
+ # if 'my_paths.list' is empty
+ ```
+
# str.join()
- name: join
returns: str