Christophe Weblog Wiki Code Publications Music
helpful `squeeze-parse-count' function
authorChristophe Rhodes <csr21@cantab.net>
Tue, 21 Oct 2014 16:48:11 +0000 (17:48 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Tue, 21 Oct 2014 16:48:11 +0000 (17:48 +0100)
use it in `squeeze-parse-players-line'

squeeze.el

index 18586145f8a92d4f5fdc5246275c2a866ac90e57..267fe2d59ce2cda7eb9b3c140364f3c9fa5d515d 100644 (file)
     (when startpos
       (squeeze-string-plistify string startpos (length string)))))
 
+(defun squeeze-parse-count (string)
+  (save-match-data
+    (let ((countpos (string-match "count%3A\\([0-9]*\\)\\>" string)))
+      (if countpos
+          (string-to-number
+           (substring string (match-beginning 1) (match-end 1)))
+        (let ((kind
+               (progn (string-match "^\\([a-z]*\\) " string)
+                      (substring string (match-beginning 1) (match-end 1)))))
+          (message "no count found in %s line" kind)
+          nil)))))
+
 (defun squeeze-parse-players-line (string)
-  (let ((countpos (string-match " count%3A\\([0-9]\\) " string))
-        (startpos (match-end 0)))
-    (unless countpos
-      (message "no count found in players line"))
-    (let ((count (string-to-number (substring string (match-beginning 1) (match-end 1))))
-          result endpos)
-      (dotimes (i (1- count))
-        (setq endpos (progn (string-match " connected%3A[0-1] " string startpos)
-                            (match-end 0)))
-        (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos endpos)) result)
-        (setq startpos endpos))
-      (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos (length string))) result)
-      result)))
+  (let ((count (squeeze-parse-count string))
+        (startpos (string-match "playerindex" string))
+        result endpos)
+    (dotimes (i (1- count))
+      (setq endpos (progn (string-match " connected%3A[0-1] " string startpos)
+                          (match-end 0)))
+      (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos endpos)) result)
+      (setq startpos endpos))
+    (push (apply 'squeeze-make-player (squeeze-string-plistify string startpos (length string))) result)
+    result))
+
 
 (defun squeeze-complete-command-at-point ()
   (save-excursion