fune/servo/components/script/dom/urlhelper.rs
Arthur Marble 8c93f25e9f servo: Merge #13307 - Code refactoring (from bubbles231:code_refactor); r=Manishearth
<!-- Please describe your changes on the following line: -->
The code was refactored to follow Rust naming conventions better.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes help fix #12379.

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because logic was not changed.

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 5457b80233f9ce6773711c7189230d9a0a63d93a
2016-09-18 22:57:59 -05:00

34 lines
2.2 KiB
Rust

/* 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/. */
use dom::bindings::str::USVString;
use std::borrow::ToOwned;
use url::{Url, quirks};
#[derive(HeapSizeOf)]
pub struct UrlHelper;
impl UrlHelper {
pub fn SameOrigin(url_a: &Url, url_b: &Url) -> bool { url_a.origin() == url_b.origin() }
pub fn Origin(url: &Url) -> USVString { USVString(quirks::origin(url)) }
pub fn Href(url: &Url) -> USVString { USVString(quirks::href(url).to_owned()) }
pub fn Hash(url: &Url) -> USVString { USVString(quirks::hash(url).to_owned()) }
pub fn Host(url: &Url) -> USVString { USVString(quirks::host(url).to_owned()) }
pub fn Port(url: &Url) -> USVString { USVString(quirks::port(url).to_owned()) }
pub fn Search(url: &Url) -> USVString { USVString(quirks::search(url).to_owned()) }
pub fn Hostname(url: &Url) -> USVString { USVString(quirks::hostname(url).to_owned()) }
pub fn Password(url: &Url) -> USVString { USVString(quirks::password(url).to_owned()) }
pub fn Pathname(url: &Url) -> USVString { USVString(quirks::pathname(url).to_owned()) }
pub fn Protocol(url: &Url) -> USVString { USVString(quirks::protocol(url).to_owned()) }
pub fn Username(url: &Url) -> USVString { USVString(quirks::username(url).to_owned()) }
pub fn SetHash(url: &mut Url, value: USVString) { quirks::set_hash(url, &value.0) }
pub fn SetHost(url: &mut Url, value: USVString) { let _ = quirks::set_host(url, &value.0); }
pub fn SetPort(url: &mut Url, value: USVString) { let _ = quirks::set_port(url, &value.0); }
pub fn SetSearch(url: &mut Url, value: USVString) { quirks::set_search(url, &value.0) }
pub fn SetPathname(url: &mut Url, value: USVString) { quirks::set_pathname(url, &value.0) }
pub fn SetHostname(url: &mut Url, value: USVString) { let _ = quirks::set_hostname(url, &value.0); }
pub fn SetPassword(url: &mut Url, value: USVString) { let _ = quirks::set_password(url, &value.0); }
pub fn SetProtocol(url: &mut Url, value: USVString) { let _ = quirks::set_protocol(url, &value.0); }
pub fn SetUsername(url: &mut Url, value: USVString) { let _ = quirks::set_username(url, &value.0); }
}