static void parseImageCandidatesFromSrcsetAttribute(const String& attribute, const CharType* attributeStart, unsigned length, Vector<ImageCandidate>& imageCandidates, Document* document) { const CharType* position = attributeStart; const CharType* attributeEnd = position + length; while (position < attributeEnd) { // 4. Splitting loop: Collect a sequence of characters that are space characters or U+002C COMMA characters. skipWhile<CharType, isHTMLSpaceOrComma<CharType>>(position, attributeEnd); if (position == attributeEnd) { // Contrary to spec language - descriptor parsing happens on each candidate, so when we reach the attributeEnd, we can exit. break; } const CharType* imageURLStart = position; // 6. Collect a sequence of characters that are not space characters, and let that be url. skipUntil<CharType, isHTMLSpace<CharType>>(position, attributeEnd); const CharType* imageURLEnd = position; DescriptorParsingResult result; // 8. If url ends with a U+002C COMMA character (,) if (isComma(*(position - 1))) { // Remove all trailing U+002C COMMA characters from url. imageURLEnd = position - 1; reverseSkipWhile<CharType, isComma>(imageURLEnd, imageURLStart); ++imageURLEnd; // If url is empty, then jump to the step labeled splitting loop. if (imageURLStart == imageURLEnd) continue; } else { skipWhile<CharType, isHTMLSpace<CharType>>(position, attributeEnd); Vector<DescriptorToken> descriptorTokens; tokenizeDescriptors(attributeStart, position, attributeEnd, descriptorTokens); // Contrary to spec language - descriptor parsing happens on each candidate. // This is a black-box equivalent, to avoid storing descriptor lists for each candidate. if (!parseDescriptors(attribute, descriptorTokens, result, document)) { if (document) { UseCounter::count(document, UseCounter::SrcsetDroppedCandidate); if (document->frame()) document->frame()->console().addMessage(ConsoleMessage::create(OtherMessageSource, ErrorMessageLevel, String("Dropped srcset candidate ") + String(imageURLStart, imageURLEnd - imageURLStart))); } continue; } } ASSERT(imageURLEnd > attributeStart); unsigned imageURLStartingPosition = imageURLStart - attributeStart; ASSERT(imageURLEnd > imageURLStart); unsigned imageURLLength = imageURLEnd - imageURLStart; imageCandidates.append(ImageCandidate(attribute, imageURLStartingPosition, imageURLLength, result, ImageCandidate::SrcsetOrigin)); // 11. Return to the step labeled splitting loop. } }
static Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(const CharType* attributeStart, unsigned length) { Vector<ImageCandidate> imageCandidates; const CharType* attributeEnd = attributeStart + length; for (const CharType* position = attributeStart; position < attributeEnd;) { // 4. Splitting loop: Collect a sequence of characters that are space characters or U+002C COMMA characters. skipWhile<CharType, isHTMLSpaceOrComma<CharType> >(position, attributeEnd); if (position == attributeEnd) { // Contrary to spec language - descriptor parsing happens on each candidate, so when we reach the attributeEnd, we can exit. break; } const CharType* imageURLStart = position; // 6. Collect a sequence of characters that are not space characters, and let that be url. skipUntil<CharType, isHTMLSpace<CharType> >(position, attributeEnd); const CharType* imageURLEnd = position; DescriptorParsingResult result; // 8. If url ends with a U+002C COMMA character (,) if (isComma(*(position - 1))) { // Remove all trailing U+002C COMMA characters from url. imageURLEnd = position - 1; reverseSkipWhile<CharType, isComma>(imageURLEnd, imageURLStart); ++imageURLEnd; // If url is empty, then jump to the step labeled splitting loop. if (imageURLStart == imageURLEnd) continue; } else { // Advancing position here (contrary to spec) to avoid an useless extra state machine step. // Filed a spec bug: https://github.com/ResponsiveImagesCG/picture-element/issues/189 ++position; Vector<StringView> descriptorTokens; tokenizeDescriptors(position, attributeEnd, descriptorTokens); // Contrary to spec language - descriptor parsing happens on each candidate. // This is a black-box equivalent, to avoid storing descriptor lists for each candidate. if (!parseDescriptors(descriptorTokens, result)) continue; } ASSERT(imageURLEnd > imageURLStart); unsigned imageURLLength = imageURLEnd - imageURLStart; imageCandidates.append(ImageCandidate(StringView(imageURLStart, imageURLLength), result, ImageCandidate::SrcsetOrigin)); // 11. Return to the step labeled splitting loop. } return imageCandidates; }