From 924f5d66750aed38f326ce31d7a5b8c0b3c130d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Mon, 13 Mar 2023 22:06:29 +0100 Subject: [PATCH] New start/stop splitting. --- member-file.scm | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/member-file.scm b/member-file.scm index 995b88c..5512504 100644 --- a/member-file.scm +++ b/member-file.scm @@ -122,11 +122,15 @@ ;; returns a list of the symbol representing the type and start/stop ;; symbol. It returns false otherwise. (define (split-start/stop-symbol s) - (cond ((eq? s 'studentstart) '(student start)) - ((eq? s 'studentstop) '(student stop)) - ((eq? s 'suspendstart) '(suspend start)) - ((eq? s 'suspendstop) '(suspend stop)) - (else #f))) + (let* ((ss (symbol->string s)) + (mstart (irregex-search (string->irregex "(start|stop)") ss))) + (if mstart + (let* ((istart (irregex-match-start-index mstart)) + (bstring (substring ss 0 istart)) + (sstring (substring ss istart))) + (list (string->symbol bstring) + (string->symbol sstring))) + #f))) ;; Processes member line adding given value v to the dictionary d ;; under key k. Special handling for start/stop symbols means given @@ -209,6 +213,9 @@ (test-equal? split-member-line (split-member-line " nick value ") '(nick "value")) (test-equal? split-member-line (split-member-line " nick value1 value2 ") '(nick "value1 value2")) (test-exn split-member-line (split-member-line "key value")) + (test-equal? split-start/stop-symbol (split-start/stop-symbol 'suspendstart) '(suspend start)) + (test-equal? split-start/stop-symbol (split-start/stop-symbol 'teststop) '(test stop)) + (test-false split-start/stop-symbol (split-start/stop-symbol 'normalkey)) )) )