From 93a4f0e82d5a7aced2b6d86dbbb0eccd93bf7093 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Sun, 16 Feb 2025 15:18:19 -0800 Subject: [PATCH] document the behavior of negative substring len Change-Id: I0777580a3aa374400586b76afdc74da5b5f6645a --- lix/libexpr/builtins/substring.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lix/libexpr/builtins/substring.md b/lix/libexpr/builtins/substring.md index a10d6b4cf..09ffee736 100644 --- a/lix/libexpr/builtins/substring.md +++ b/lix/libexpr/builtins/substring.md @@ -5,12 +5,18 @@ args: [start, len, s] Return the substring of *s* from character position *start* (zero-based) up to but not including *start + len*. If *start* is greater than the length of the string, an empty string is returned, -and if *start + len* lies beyond the end of the string, only the -substring up to the end of the string is returned. *start* must be -non-negative. For example, +and if *start + len* lies beyond the end of the string or *len* +is negative, only the substring up to the end of the string is +returned. *start* must be non-negative. For example, ```nix builtins.substring 0 3 "nixos" ``` -evaluates to `"nix"`. +evaluates to `"nix"`, and + +```nix +builtins.substring 3 (-1) "nixos" +``` + +evaluates to `"os"`.