Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: third_party/WebKit/Source/core/dom/custom/CustomElement.cpp

Issue 1914383002: Implement CustomElement::isValidName() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PCENChar
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/dom/custom/CustomElement.h" 5 #include "core/dom/custom/CustomElement.h"
6 6
7 #include "platform/text/Character.h" 7 #include "platform/text/Character.h"
8 #include "wtf/text/AtomicStringHash.h"
8 9
9 namespace blink { 10 namespace blink {
10 11
12 bool CustomElement::isValidName(const AtomicString& name)
13 {
14 if (!isPotentialCustomElementName(name))
15 return false;
16
17 // https://html.spec.whatwg.org/multipage/scripting.html#valid-custom-elemen t-name
18 DEFINE_STATIC_LOCAL(HashSet<AtomicString>, hyphenContainingElementNames, ()) ;
19 if (hyphenContainingElementNames.isEmpty()) {
20 hyphenContainingElementNames.add("annotation-xml");
21 hyphenContainingElementNames.add("color-profile");
22 hyphenContainingElementNames.add("font-face");
23 hyphenContainingElementNames.add("font-face-src");
24 hyphenContainingElementNames.add("font-face-uri");
25 hyphenContainingElementNames.add("font-face-format");
26 hyphenContainingElementNames.add("font-face-name");
27 hyphenContainingElementNames.add("missing-glyph");
28 }
29
30 return !hyphenContainingElementNames.contains(name);
31 }
32
11 bool CustomElement::isPotentialCustomElementName(const AtomicString& name) 33 bool CustomElement::isPotentialCustomElementName(const AtomicString& name)
12 { 34 {
13 if (!name.length() || name[0] < 'a' || name[0] > 'z') 35 if (!name.length() || name[0] < 'a' || name[0] > 'z')
14 return false; 36 return false;
15 37
16 bool hasHyphens = false; 38 bool hasHyphens = false;
17 for (size_t i = 1; i < name.length(); ) { 39 for (size_t i = 1; i < name.length(); ) {
18 UChar32 ch; 40 UChar32 ch;
19 if (name.is8Bit()) 41 if (name.is8Bit())
20 ch = name[i++]; 42 ch = name[i++];
21 else 43 else
22 U16_NEXT(name.characters16(), i, name.length(), ch); 44 U16_NEXT(name.characters16(), i, name.length(), ch);
23 if (ch == '-') 45 if (ch == '-')
24 hasHyphens = true; 46 hasHyphens = true;
25 else if (!Character::isPotentialCustomElementNameChar(ch)) 47 else if (!Character::isPotentialCustomElementNameChar(ch))
26 return false; 48 return false;
27 } 49 }
28 return hasHyphens; 50 return hasHyphens;
29 } 51 }
30 52
31 } // namespace blink 53 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698