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

Side by Side Diff: Source/core/html/parser/HTMLParserIdioms.h

Issue 293423002: Refactor srcset parser to align it with spec changes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added tests and fixed a bug Created 6 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 /* 1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 18 matching lines...) Expand all
29 #include "platform/Decimal.h" 29 #include "platform/Decimal.h"
30 #include "wtf/Forward.h" 30 #include "wtf/Forward.h"
31 #include "wtf/text/WTFString.h" 31 #include "wtf/text/WTFString.h"
32 32
33 namespace WTF { 33 namespace WTF {
34 class TextEncoding; 34 class TextEncoding;
35 } 35 }
36 36
37 namespace WebCore { 37 namespace WebCore {
38 38
39 // Space characters as defined by the HTML specification.
40 bool isHTMLSpace(UChar);
41 bool isHTMLLineBreak(UChar);
42 bool isNotHTMLSpace(UChar);
43
44 // Strip leading and trailing whitespace as defined by the HTML specification. 39 // Strip leading and trailing whitespace as defined by the HTML specification.
45 String stripLeadingAndTrailingHTMLSpaces(const String&); 40 String stripLeadingAndTrailingHTMLSpaces(const String&);
46 template<size_t inlineCapacity> 41 template<size_t inlineCapacity>
47 String stripLeadingAndTrailingHTMLSpaces(const Vector<UChar, inlineCapacity>& ve ctor) 42 String stripLeadingAndTrailingHTMLSpaces(const Vector<UChar, inlineCapacity>& ve ctor)
48 { 43 {
49 return stripLeadingAndTrailingHTMLSpaces(StringImpl::create8BitIfPossible(ve ctor)); 44 return stripLeadingAndTrailingHTMLSpaces(StringImpl::create8BitIfPossible(ve ctor));
50 } 45 }
51 46
52 // An implementation of the HTML specification's algorithm to convert a number t o a string for number and range types. 47 // An implementation of the HTML specification's algorithm to convert a number t o a string for number and range types.
53 String serializeForNumberType(const Decimal&); 48 String serializeForNumberType(const Decimal&);
54 String serializeForNumberType(double); 49 String serializeForNumberType(double);
55 50
56 // Convert the specified string to a decimal/double. If the conversion fails, th e return value is fallback value or NaN if not specified. 51 // Convert the specified string to a decimal/double. If the conversion fails, th e return value is fallback value or NaN if not specified.
57 // Leading or trailing illegal characters cause failure, as does passing an empt y string. 52 // Leading or trailing illegal characters cause failure, as does passing an empt y string.
58 // The double* parameter may be 0 to check if the string can be parsed without g etting the result. 53 // The double* parameter may be 0 to check if the string can be parsed without g etting the result.
59 Decimal parseToDecimalForNumberType(const String&, const Decimal& fallbackValue = Decimal::nan()); 54 Decimal parseToDecimalForNumberType(const String&, const Decimal& fallbackValue = Decimal::nan());
60 double parseToDoubleForNumberType(const String&, double fallbackValue = std::num eric_limits<double>::quiet_NaN()); 55 double parseToDoubleForNumberType(const String&, double fallbackValue = std::num eric_limits<double>::quiet_NaN());
61 56
62 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers 57 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
63 bool parseHTMLInteger(const String&, int&); 58 bool parseHTMLInteger(const String&, int&);
64 59
65 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-nega tive-integers 60 // http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-nega tive-integers
66 bool parseHTMLNonNegativeInteger(const String&, unsigned&); 61 bool parseHTMLNonNegativeInteger(const String&, unsigned&);
67 62
68 typedef Vector<pair<String, String> > HTMLAttributeList; 63 typedef Vector<pair<String, String> > HTMLAttributeList;
69 // The returned encoding might not be valid. 64 // The returned encoding might not be valid.
70 WTF::TextEncoding encodingFromMetaAttributes(const HTMLAttributeList&); 65 WTF::TextEncoding encodingFromMetaAttributes(const HTMLAttributeList&);
71 66
72 // Inline implementations of some of the functions declared above. 67 // Space characters as defined by the HTML specification.
73
74 template<typename CharType> 68 template<typename CharType>
75 inline bool isHTMLSpace(CharType character) 69 inline bool isHTMLSpace(CharType character)
76 { 70 {
77 // Histogram from Apple's page load test combined with some ad hoc browsing some other test suites. 71 // Histogram from Apple's page load test combined with some ad hoc browsing some other test suites.
78 // 72 //
79 // 82%: 216330 non-space characters, all > U+0020 73 // 82%: 216330 non-space characters, all > U+0020
80 // 11%: 30017 plain space characters, U+0020 74 // 11%: 30017 plain space characters, U+0020
81 // 5%: 12099 newline characters, U+000A 75 // 5%: 12099 newline characters, U+000A
82 // 2%: 5346 tab characters, U+0009 76 // 2%: 5346 tab characters, U+0009
83 // 77 //
84 // No other characters seen. No U+000C or U+000D, and no other control chara cters. 78 // No other characters seen. No U+000C or U+000D, and no other control chara cters.
85 // Accordingly, we check for non-spaces first, then space, then newline, the n tab, then the other characters. 79 // Accordingly, we check for non-spaces first, then space, then newline, the n tab, then the other characters.
86 80
87 return character <= ' ' && (character == ' ' || character == '\n' || charact er == '\t' || character == '\r' || character == '\f'); 81 return character <= ' ' && (character == ' ' || character == '\n' || charact er == '\t' || character == '\r' || character == '\f');
88 } 82 }
89 83
90 template<typename CharType> 84 template<typename CharType>
85 inline bool isComma(CharType character)
eseidel 2014/05/28 22:24:59 inline is only a compiler hint and only has an eff
Yoav Weiss 2014/05/29 05:17:40 It's inline here since I also use it as a standalo
86 {
87 return character == ',';
88 }
89
90 template<typename CharType>
91 inline bool isHTMLSpaceOrComma(CharType character) 91 inline bool isHTMLSpaceOrComma(CharType character)
92 { 92 {
93 return isHTMLSpace<CharType>(character) || character == ','; 93 return isComma(character) || isHTMLSpace<CharType>(character);
94 } 94 }
95 95
96 inline bool isHTMLLineBreak(UChar character) 96 inline bool isHTMLLineBreak(UChar character)
97 { 97 {
98 return character <= '\r' && (character == '\n' || character == '\r'); 98 return character <= '\r' && (character == '\n' || character == '\r');
99 } 99 }
100 100
101 template<typename CharType> 101 template<typename CharType>
102 inline bool isNotHTMLSpace(CharType character) 102 inline bool isNotHTMLSpace(CharType character)
103 { 103 {
(...skipping 22 matching lines...) Expand all
126 inline static String attemptStaticStringCreation(const String str) 126 inline static String attemptStaticStringCreation(const String str)
127 { 127 {
128 if (!str.is8Bit()) 128 if (!str.is8Bit())
129 return attemptStaticStringCreation(str.characters16(), str.length(), For ce16Bit); 129 return attemptStaticStringCreation(str.characters16(), str.length(), For ce16Bit);
130 return attemptStaticStringCreation(str.characters8(), str.length()); 130 return attemptStaticStringCreation(str.characters8(), str.length());
131 } 131 }
132 132
133 133
134 } 134 }
135 #endif 135 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698