mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add str.rs.
This commit is contained in:
parent
59184bf6e1
commit
951d35902c
1 changed files with 21 additions and 0 deletions
21
src/components/util/str.rs
Normal file
21
src/components/util/str.rs
Normal file
|
@ -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 ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue