aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMs2ger <ms2ger@gmail.com>2014-02-14 13:20:48 +0100
committerMs2ger <ms2ger@gmail.com>2014-02-14 13:20:48 +0100
commit951d35902c8d160441478126a32a0723c11278f1 (patch)
tree346c05aa8cd086cc0a72f1b16ececce02c17a262 /src
parent59184bf6e1af4e0e8aef57ff3f7b8724f5762cee (diff)
downloadservo-951d35902c8d160441478126a32a0723c11278f1.tar.gz
servo-951d35902c8d160441478126a32a0723c11278f1.zip
Add str.rs.
Diffstat (limited to 'src')
-rw-r--r--src/components/util/str.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/components/util/str.rs b/src/components/util/str.rs
new file mode 100644
index 00000000000..13272d8ec42
--- /dev/null
+++ b/src/components/util/str.rs
@@ -0,0 +1,21 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+pub type DOMString = ~str;
+
+pub fn null_str_as_empty(s: &Option<DOMString>) -> DOMString {
+ // We don't use map_default because it would allocate ~"" even for Some.
+ match *s {
+ Some(ref s) => s.clone(),
+ None => ~""
+ }
+}
+
+pub fn null_str_as_empty_ref<'a>(s: &'a Option<DOMString>) -> &'a str {
+ match *s {
+ Some(ref s) => s.as_slice(),
+ None => &'a ""
+ }
+}
+