aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2024-09-13 22:54:16 +0100
committerArun Isaac2024-09-13 22:54:16 +0100
commit823560e068c9843b755a1af285a1b1d2157811f2 (patch)
tree8a4805747816504f1d00fa56f7208b3f775b7d65
parent434bbd348ecf4631c890837894360d28af2f2e58 (diff)
downloadravanan-823560e068c9843b755a1af285a1b1d2157811f2.tar.gz
ravanan-823560e068c9843b755a1af285a1b1d2157811f2.tar.lz
ravanan-823560e068c9843b755a1af285a1b1d2157811f2.zip
utils: Add string-trim-prefix.
* ravanan/utils.scm (string-trim-prefix): New public function.
-rw-r--r--ravanan/utils.scm9
1 files changed, 8 insertions, 1 deletions
diff --git a/ravanan/utils.scm b/ravanan/utils.scm
index d56378e..5ae3c20 100644
--- a/ravanan/utils.scm
+++ b/ravanan/utils.scm
@@ -20,9 +20,16 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:use-module (ice-9 match)
- #:export (json-ref
+ #:export (string-trim-prefix
+ json-ref
call-with-temporary-file))
+(define (string-trim-prefix prefix str)
+ "Remove @var{prefix} from @var{str} if it exists. Else, return @var{str} as is."
+ (if (string-prefix? prefix str)
+ (substring str (string-length prefix))
+ str))
+
(define (json-ref scm . keys)
"Extract subtree of JSON @var{scm} that is addressed by @var{keys}."
(match keys