Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upParse A Size Attribute #10827
Parse A Size Attribute #10827
Conversation
highfive
commented
Apr 24, 2016
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @larsbergstrom (or someone else) soon. |
highfive
commented
Apr 24, 2016
|
Heads up! This PR modifies the following files:
|
highfive
commented
Apr 24, 2016
|
For the benefit of anyone else reading, copied from my last email:
If there are particular things which you are looking for suggestions about, please state them :) |
|
|
|
@jdm : could you see if the function declaration looks right , and also - unparsed_size_list ? |
|
I strongly recommend writing unit tests for your code so you have some idea of exactly what it's doing. You can do this directly in use script::dom::htmlimageelement::parse_a_sizes_attribute;
#[test]
fn some_parse_sizes_test() {
let result = parse_a_sizes_attribute(...);
assert!(/* something about result that is boolean */);
}and run it with Now, as for the code: As for the whitespace checks, we can use iterators to our advantage. The code looks like it should be equivalent to let whitespace = unparsed_size.chars().rev().take_while(|c| util::str::char_is_whitespace(c)).count();
let trimmed = unparsed_size.chars().take(unparsed_size.chars().count() - whitespace).as_str();
|
|
The iterator was giving error , so included let mut iter = Parser::new(input); |
|
We don't want to use |
|
@jdm : Thanks ! |
|
Yes. Here's where we can use the cssparser::Parser API effectively - Length::parse_non_negative accepts a reference to a |
|
@jdm |
|
My mistake for not trying it out in https://play.rust-lang.org/ first. This works: let s = "foo bar ".to_owned();
let whitespace = s.chars().rev().take_while(|c| *c == ' ').count();
let nonwhitespace: String = s.chars().take(s.chars().count() - whitespace).collect();
println!("|{}|", nonwhitespace); |
|
@jdm Thanks ! sneha |
|
I strongly recommend writing unit tests that put your code through its paces. Start with the case of a single length value, then try two comma-separated values where the first one has a media expression, then three. Also try the cases where there's a parse error expected, and trailing whitespace, etc. http://bitsofco.de/the-srcset-and-sizes-attributes/ has a great example that shows some sample values that can exist in the |
|
|
||
| let mut parse_each = Parser::new(&trimmed); | ||
| let each_media_query = parse_each.try(MediaQuery::parse); |
This comment has been minimized.
This comment has been minimized.
jdm
May 3, 2016
Member
I'll point out that a media query is different than a media expression. We don't want to try to parse a whole media query here; I mentioned Expression::parse for a reason.
|
|
|
Also, shouldn't the
|
|
|
|
What happened here? |
sneha1302 commentedApr 24, 2016
Hi ,
Have started the parse_a_size_attribute for image load conform , but need suggestions and so creating the pull Request .
This change is