mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
gpgscm: Add and use opcode for reversing a list in place.
* tests/gpgscm/lib.scm (string-split-pln): Use 'reverse!'. (string-rtrim): Likewise. * tests/gpgscm/opdefines.h (reverse!): New opcode. * tests/gpgscm/scheme.c (opexe_0): Handle new opcode. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
3e91019a92
commit
e1bb9326dc
3 changed files with 8 additions and 4 deletions
|
@ -95,10 +95,10 @@
|
|||
(let ((length (string-length haystack)))
|
||||
(define (split acc offset n)
|
||||
(if (>= offset length)
|
||||
(reverse acc)
|
||||
(reverse! acc)
|
||||
(let ((i (lookahead haystack offset)))
|
||||
(if (or (eq? i #f) (= 0 n))
|
||||
(reverse (cons (substring haystack offset length) acc))
|
||||
(reverse! (cons (substring haystack offset length) acc))
|
||||
(split (cons (substring haystack offset i) acc)
|
||||
(+ i 1) (- n 1))))))
|
||||
(split '() 0 n)))
|
||||
|
@ -168,10 +168,10 @@
|
|||
(define (string-rtrim predicate s)
|
||||
(if (string=? s "")
|
||||
""
|
||||
(let loop ((s' (reverse (string->list s))))
|
||||
(let loop ((s' (reverse! (string->list s))))
|
||||
(if (predicate (car s'))
|
||||
(loop (cdr s'))
|
||||
(list->string (reverse s'))))))
|
||||
(list->string (reverse! s'))))))
|
||||
(assert (string=? "" (string-rtrim char-whitespace? "")))
|
||||
(assert (string=? "foo" (string-rtrim char-whitespace? "foo ")))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue