Auto merge of #23855 - sreeise:media_frag_string, r=ferjm

Changed DOMString usages to string in MediaFragmentParser

<!-- Please describe your changes on the following line: -->
Changed `DOMString` usages to `String`/`&str`.

---
<!-- 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 fix #23834 (GitHub issue number if applicable)

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

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

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23855)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-07-26 08:22:09 -04:00 committed by GitHub
commit 2981fe87ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 30 deletions

View file

@ -1526,13 +1526,13 @@ impl HTMLMediaElement {
if let Some(servo_url) = self.resource_url.borrow().as_ref() {
let fragment = MediaFragmentParser::from(servo_url);
if let Some(id) = fragment.id() {
if audio_track.id() == id {
if audio_track.id() == DOMString::from(id) {
self.AudioTracks()
.set_enabled(self.AudioTracks().len() - 1, true);
}
}
if fragment.tracks().contains(&audio_track.kind()) {
if fragment.tracks().contains(&audio_track.kind().into()) {
self.AudioTracks()
.set_enabled(self.AudioTracks().len() - 1, true);
}
@ -1582,10 +1582,10 @@ impl HTMLMediaElement {
if let Some(servo_url) = self.resource_url.borrow().as_ref() {
let fragment = MediaFragmentParser::from(servo_url);
if let Some(id) = fragment.id() {
if track.id() == id {
if track.id() == DOMString::from(id) {
self.VideoTracks().set_selected(0, true);
}
} else if fragment.tracks().contains(&track.kind()) {
} else if fragment.tracks().contains(&track.kind().into()) {
self.VideoTracks().set_selected(0, true);
}
}

View file

@ -2,7 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::str::DOMString;
use chrono::NaiveDateTime;
use servo_url::ServoUrl;
use std::borrow::Cow;
@ -39,19 +38,19 @@ pub struct SpatialClipping {
#[derive(Clone, Debug, Default, PartialEq)]
pub struct MediaFragmentParser {
id: Option<DOMString>,
tracks: Vec<DOMString>,
id: Option<String>,
tracks: Vec<String>,
spatial: Option<SpatialClipping>,
start: Option<f64>,
end: Option<f64>,
}
impl MediaFragmentParser {
pub fn id(&self) -> Option<DOMString> {
pub fn id(&self) -> Option<String> {
self.id.clone()
}
pub fn tracks(&self) -> &Vec<DOMString> {
pub fn tracks(&self) -> &Vec<String> {
self.tracks.as_ref()
}
@ -80,8 +79,8 @@ impl MediaFragmentParser {
parser.spatial = Some(spatial);
}
},
b"id" => parser.id = Some(DOMString::from(value.as_ref())),
b"track" => parser.tracks.push(DOMString::from(value.as_ref())),
b"id" => parser.id = Some(value.to_string()),
b"track" => parser.tracks.push(value.to_string()),
_ => {},
}
}
@ -219,39 +218,25 @@ fn decode_octets(bytes: &[u8]) -> Vec<(Cow<str>, Cow<str>)> {
}
// Parse a full URL or a relative URL without a base retaining the query and/or fragment.
fn split_url(s: &str) -> (DOMString, DOMString) {
fn split_url(s: &str) -> (&str, &str) {
if s.contains('?') || s.contains('#') {
let mut query = DOMString::new();
let mut fragment = DOMString::new();
for (index, byte) in s.bytes().enumerate() {
if byte == b'?' {
let mut found = false;
let partial = &s[index + 1..];
for (i, byte) in partial.bytes().enumerate() {
if byte == b'#' {
found = true;
query.push_str(&partial[..i]);
fragment.push_str(&partial[i + 1..]);
return (&partial[..i], &partial[i + 1..]);
}
}
if found {
break;
} else {
query.push_str(partial);
break;
}
return (partial, "");
}
if byte == b'#' {
fragment.push_str(&s[index + 1..]);
break;
return ("", &s[index + 1..]);
}
}
(query, fragment)
} else {
(DOMString::new(), DOMString::from(s))
}
("", s)
}
fn is_byte_number(byte: u8) -> bool {