aboutsummaryrefslogtreecommitdiff
path: root/src/api/encoding.rs
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-03-26 22:32:09 +0100
committerTrinity Pointard <trinity.pointard@gmail.com>2021-04-06 05:26:48 +0200
commita74eccfd6e1cd438912800ea4f96a2f86d267d12 (patch)
treedb1a0ccea1b29c8916ed3246ff71ea66b3323bac /src/api/encoding.rs
parentee9b685994a95787cd735ee17dc43875f549514f (diff)
downloadgarage-a74eccfd6e1cd438912800ea4f96a2f86d267d12.tar.gz
garage-a74eccfd6e1cd438912800ea4f96a2f86d267d12.zip
document api crate
Diffstat (limited to 'src/api/encoding.rs')
-rw-r--r--src/api/encoding.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/api/encoding.rs b/src/api/encoding.rs
index 25999207..63c5dee2 100644
--- a/src/api/encoding.rs
+++ b/src/api/encoding.rs
@@ -1,9 +1,13 @@
+//! Module containing various helpers for encoding
+
+/// Escape &str for xml inclusion
pub fn xml_escape(s: &str) -> String {
s.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
}
+/// Encode &str for use in a URI
pub fn uri_encode(string: &str, encode_slash: bool) -> String {
let mut result = String::with_capacity(string.len() * 2);
for c in string.chars() {
@@ -24,6 +28,7 @@ pub fn uri_encode(string: &str, encode_slash: bool) -> String {
result
}
+/// Encode &str either as an uri, or a valid string for xml inclusion
pub fn xml_encode_key(k: &str, urlencode: bool) -> String {
if urlencode {
uri_encode(k, true)