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.scm47
1 files changed, 47 insertions, 0 deletions
diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm
index 589f1e7..d8f4da7 100644
--- a/modules/language/python/string.scm
+++ b/modules/language/python/string.scm
@@ -5,6 +5,7 @@
#:use-module (ice-9 match)
#:use-module (language python list)
#:use-module (language python exceptions)
+ #:use-module (language python for)
#:use-module (parser stis-parser)
#:export (py-format py-capitalize py-center py-endswith
py-expandtabs py-find py-rfind
@@ -517,6 +518,52 @@
(define-method (equal? x (o <py-string>))
(equal? (slot-ref o 'str) x))
+(define-class <string-iter> (<py-string>) str i d)
+
+(define-method (write (o <string-iter>) . l)
+ (define port (if (null? l) #t (car l)))
+ (for ((x : o)) ((l '()))
+ (cons (string-ref x 0) l)
+ #:final
+ (format port "iter(~s)" (list->string (reverse l)))))
+
+(define-method (wrap-in (o <string-iter> ))
+ (let ((out (make <string-iter>)))
+ (slot-set! out 'str (slot-ref o 'str))
+ (slot-set! out 'i (slot-ref o 'i))
+ (slot-set! out 'd (slot-ref o 'd))
+ out))
+
+(define-method (wrap-in (s <string>))
+ (let ((out (make <string-iter>)))
+ (slot-set! out 'str s)
+ (slot-set! out 'i 0)
+ (slot-set! out 'd 1)
+ out))
+
+(define-method (py-reversed (s <string>))
+ (let ((out (make <string-iter>)))
+ (slot-set! out 'str s)
+ (slot-set! out 'i (- (string-length s) 1))
+ (slot-set! out 'd -1)
+ out))
+
+(define-method (next (o <string-iter>))
+ (let ((i (slot-ref o 'i ))
+ (d (slot-ref o 'd))
+ (str (slot-ref o 'str)))
+ (if (> d 0)
+ (if (< i (string-length str))
+ (let ((ret (string-ref str i)))
+ (slot-set! o 'i (+ i d))
+ (list->string (list ret)))
+ (throw StopIteration))
+ (if (>= i 0)
+ (let ((ret (string-ref str i)))
+ (slot-set! o 'i (+ i d))
+ (list->string (list ret)))
+ (throw StopIteration)))))
+
(define (pystring-listing)
(let ((l (to-pylist
(map symbol->string