Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit usages of unicode case-changing methods. #17883

Merged
merged 4 commits into from Aug 2, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Minor refactorings for 'data-' attribute logic.

  • Loading branch information
frewsxcv committed Jul 29, 2017
commit 6238035612a45ae3757739f6a0c17b7b6feda8ec
@@ -32,7 +32,6 @@ use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::default::Default;
use std::rc::Rc;
use style::attr::AttrValue;
@@ -374,11 +373,15 @@ impl HTMLElementMethods for HTMLElement {

// https://html.spec.whatwg.org/multipage/#attr-data-*

static DATA_PREFIX: &str = "data-";
static DATA_HYPHEN_SEPARATOR: char = '\x2d';

fn to_snake_case(name: DOMString) -> DOMString {
let mut attr_name = "data-".to_owned();
let mut attr_name = String::with_capacity(name.len() + DATA_PREFIX.len());
attr_name.push_str(DATA_PREFIX);
for ch in name.chars() {
if ch.is_ascii_uppercase() {
attr_name.push('\x2d');
attr_name.push(DATA_HYPHEN_SEPARATOR);
attr_name.push(ch.to_ascii_lowercase());
} else {
attr_name.push(ch);
@@ -394,19 +397,19 @@ fn to_snake_case(name: DOMString) -> DOMString {
// without the data prefix.

fn to_camel_case(name: &str) -> Option<DOMString> {
if !name.starts_with("data-") {
if !name.starts_with(DATA_PREFIX) {
return None;
}
let name = &name[5..];
let has_uppercase = name.chars().any(|curr_char| curr_char.is_ascii_uppercase());
if has_uppercase {
return None;
}
let mut result = "".to_owned();
let mut result = String::with_capacity(name.len().saturating_sub(DATA_PREFIX.len()));
let mut name_chars = name.chars();
while let Some(curr_char) = name_chars.next() {
//check for hyphen followed by character
if curr_char == '\x2d' {
if curr_char == DATA_HYPHEN_SEPARATOR {
if let Some(next_char) = name_chars.next() {
if next_char.is_ascii_lowercase() {
result.push(next_char.to_ascii_uppercase());
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.