Skip to content

Instantly share code, notes, and snippets.

@gongo
Created January 28, 2013 13:27
Show Gist options
  • Save gongo/4655484 to your computer and use it in GitHub Desktop.
Save gongo/4655484 to your computer and use it in GitHub Desktop.
AirPlay Protocol ? で使われてるメジャーなのかどうかわからない text/parameters を parse するの雰囲気で書いたけどもっと何かあるだろって感じになった。
(defun airplay/protocol:parse-text-parameters ()
"\
Parse string in current buffer.
Returns the text/parameters list.
eg.
(buffer-string)
;; => \"duration: 83.124794\\nposition: 14.467000\\n\"
(airplay/protocol:parse-text-parameters)
;; => ((\"duration\" . \"0.000000\") (\"position\" . \"0.000000\"))
"
(let ((params '()))
(save-excursion
(perform-replace "\\`\\(?:\\\s-\\|\n\\)+\\|\\(?:\\\s-\\|\n\\)+\\'" "" nil t nil)
(goto-char (point-min))
(while (re-search-forward "^\\([^:\\\s ]+\\)[\\\s ]*:[\\\s ]*\\([^\\\s ]+\\)$" nil t)
(let ((name (match-string 1)) (body (match-string 2)))
(setq params (append params `((,name . ,body))))
(forward-line))))
params))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment