-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42eded9
commit 664ac6e
Showing
4 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(in-package #:prometheus.formats.text) | ||
|
||
;; http://cl-cookbook.sourceforge.net/strings.html#manip | ||
(defun replace-all (string part replacement &key (test #'char=)) | ||
"Returns a new string in which all the occurences of the part | ||
is replaced with replacement." | ||
(with-output-to-string (out) | ||
(loop with part-length = (length part) | ||
for old-pos = 0 then (+ pos part-length) | ||
for pos = (search part string | ||
:start2 old-pos | ||
:test test) | ||
do (write-string string out | ||
:start old-pos | ||
:end (or pos (length string))) | ||
when pos do (write-string replacement out) | ||
while pos))) | ||
|
||
(defun escape-metric-help (help) | ||
(replace-all (replace-all help "\\" "\\\\") | ||
#.(string #\Newline) "\\n")) | ||
|
||
(defun escape-label-value (help) | ||
(replace-all | ||
(replace-all | ||
(replace-all | ||
help | ||
"\\" "\\\\") | ||
#.(string #\Newline) "\\n") | ||
"\"" "\\\"")) |
This file contains 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
This file contains 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