summaryrefslogtreecommitdiff
path: root/modules/language/python/string.scm
diff options
context:
space:
mode:
Diffstat (limited to 'modules/language/python/string.scm')
-rw-r--r--modules/language/python/string.scm24
1 files changed, 13 insertions, 11 deletions
diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm
index c68b9ae..156cc43 100644
--- a/modules/language/python/string.scm
+++ b/modules/language/python/string.scm
@@ -3,7 +3,8 @@
#:use-module (oop pf-objects)
#:use-module (ice-9 match)
#:use-module (parser stis-parser)
- #:export (py-format))
+ #:export (py-format py-capitalize py-center py-endswith
+ py-expandtabs py-find))
(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
@@ -12,7 +13,6 @@
(define-method (f (o <string>) . u) code ...)
(define-method (f (o <p>) . l) (apply (ref o 'n) l))))
-#|
(define-py (py-capitalize capitalize o)
(string-capitalize o))
@@ -23,7 +23,7 @@
(n (string-length o))
(w (if (< w n) n w))
(d (- w n))
- (e (floor-quotient (- w n) / 2))
+ (e (floor-quotient (- w n) 2))
(s (make-string w #\space)))
(let lp ((i 0) (j e))
(if (< i n)
@@ -34,19 +34,21 @@
-;py-decode
-;py-encode
+;;;py-decode
+;;;py-encode
+
+
(define-py (py-endswith endswith o (suff <string>) . l)
- (let ((n (string-length o))
- (ns (string-length suff))
- (f (lambda (x) (< x 0) (+ n x) x)))
+ (let* ((n (string-length o))
+ (ns (string-length suff))
+ (f (lambda (x) (< x 0) (+ n x) x)))
(call-with-values (lambda ()
(match l
(() (values 0 n ))
((x) (values (f x) n ))
((x y) (values (f x) (f y)))))
(lambda (start end)
- (string-suffix? o suff start end)))))
+ (string-suffix? suff o 0 ns start end)))))
(define-py (py-expandtabs expandtabs s . l)
(let* ((tabsize (match l (() 8) ((x) x)))
@@ -61,7 +63,8 @@
(list->string (reverse r))))))
(define-py (py-find find s sub . l)
- (let ((f (lambda (x) (< x 0) (+ n x) x)))
+ (let* ((n (string-length s))
+ (f (lambda (x) (< x 0) (+ n x) x)))
(call-with-values (lambda ()
(match l
(() (values 0 n ))
@@ -71,7 +74,6 @@
(aif it (string-contains s sub start end)
it
-1)))))
-|#
(define i (f-list #:i (mk-token (f+ (f-reg! "[0-9]")))))
(define s (f-list #:s (mk-token (f+ (f-not! (f-tag "}"))))))