From 63453564ee697ebf4741f082b8d678ed15455a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 13 Oct 2023 07:59:09 +0100 Subject: [PATCH] docs: document out of bounds behavior in str.substring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe LaĆ­ns --- docs/yaml/elementary/str.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/yaml/elementary/str.yml b/docs/yaml/elementary/str.yml index 83ab3dd64..9d059cc09 100644 --- a/docs/yaml/elementary/str.yml +++ b/docs/yaml/elementary/str.yml @@ -164,6 +164,9 @@ methods: The method accepts negative values where negative `start` is relative to the end of string `len(string) - start` as well as negative `end`. + If `start` or `end` are out of bounds, the position of the closest character will be used. + If `start` is bigger than `end`, the result will be an empty substring. + example: | ```meson # Similar to the Python str[start:end] syntax @@ -180,6 +183,15 @@ methods: string.substring(1, -1) # => 'ooba' ``` + Example with out of bound values: + + ```meson + string = 'foobar' + string.substring(64) # => '' + string.substring(0, 64) # => 'foobar' + string.substring(64, 0) # => '' + ``` + optargs: start: type: int