Created
January 28, 2013 13:27
-
-
Save gongo/4655484 to your computer and use it in GitHub Desktop.
AirPlay Protocol ? で使われてるメジャーなのかどうかわからない text/parameters を parse するの雰囲気で書いたけどもっと何かあるだろって感じになった。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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