Skip to content

Commit

Permalink
feat: Add string-butlast utility
Browse files Browse the repository at this point in the history
  • Loading branch information
cmpitg committed May 8, 2016
1 parent 328491e commit e227359
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/Ulquikit-Utils.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ relative good performance.
#:file?
#:write-file
#:function-name
#:alist-get))
#:alist-get
#:string-butlast))
(defpackage #:ulqui/utils-tests
(:use :cl
Expand Down Expand Up @@ -237,7 +238,7 @@ E.g.
(declare (function fsymbol))
(let ((name-tmp (nth 1 (split-sequence #\Space
(format nil "~(~A~)" fsymbol)))))
(subseq name-tmp 0 (1- (length name-tmp)))))
(string-butlast name-tmp)))
(in-package #:ulqui/utils-tests)
Expand All @@ -247,6 +248,25 @@ E.g.
(in-package #:ulqui/utils)
(defun string-butlast (str)
"Returns the string without the last character. If the string is
zero-length, returns an empty string."
(declare (string str))
(the string
(let ((length (length str)))
(if (zerop length)
""
(subseq str 0 (1- length))))))
(in-package #:ulqui/utils-tests)
(define-test test-string-butlast
(assert-equal "" (string-butlast ""))
(assert-equal "" (string-butlast "a"))
(assert-equal "a" (string-butlast "ab")))
(in-package #:ulqui/utils)
(defun alist-get (alist key &key (test 'eql))
"Returns corresponding value for a key, could be used with `setf'. This
function aliases `alexandria:assoc-value'."
Expand Down

0 comments on commit e227359

Please sign in to comment.