///|
/// Escape a HELP payload according to the Prometheus/OpenMetrics text grammar.
///
/// HELP lines escape backslash and line-feed. Double quotes have no special
/// meaning in HELP text and are intentionally kept unchanged.
fn escape_help(value : String) -> String {
let output = StringBuilder()
for char in value {
match char {
'\\' => output.write_string("\\\\")
'\n' => output.write_string("\\n")
_ => output.write_char(char)
}
}
output.to_string()
}
///|
/// Escape a quoted label value according to the text exposition grammar.
fn escape_label_value(value : String) -> String {
let output = StringBuilder()
for char in value {
match char {
'\\' => output.write_string("\\\\")
'"' => output.write_string("\\\"")
'\n' => output.write_string("\\n")
_ => output.write_char(char)
}
}
output.to_string()
}