| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 3 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef HTMLEntityParser_h | 27 #ifndef HTMLEntityParser_h |
| 28 #define HTMLEntityParser_h | 28 #define HTMLEntityParser_h |
| 29 | 29 |
| 30 #include "platform/text/SegmentedString.h" | 30 #include "platform/text/SegmentedString.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 | 33 |
| 34 class DecodedHTMLEntity { | 34 class HTMLEntityParser { |
| 35 public: |
| 36 typedef Vector<UChar, 32> OutputBuffer; |
| 37 |
| 38 HTMLEntityParser(); |
| 39 ~HTMLEntityParser(); |
| 40 |
| 41 void reset(); |
| 42 bool parse(SegmentedString&); |
| 43 |
| 44 const OutputBuffer& result() const { return m_buffer; } |
| 45 |
| 35 private: | 46 private: |
| 36 // HTML entities contain at most four UTF-16 code units. | 47 enum EntityState { |
| 37 static const unsigned kMaxLength = 4; | 48 Initial, |
| 49 Numeric, |
| 50 PossiblyHex, |
| 51 Hex, |
| 52 Decimal, |
| 53 Named |
| 54 }; |
| 38 | 55 |
| 39 public: | 56 void finalizeNumericEntity(); |
| 40 DecodedHTMLEntity() : length(0) { } | 57 void finalizeNamedEntity(); |
| 41 | 58 |
| 42 bool isEmpty() const { return !length; } | 59 EntityState m_state; |
| 43 | 60 UChar32 m_result; |
| 44 void append(UChar c) | 61 OutputBuffer m_buffer; |
| 45 { | |
| 46 RELEASE_ASSERT(length < kMaxLength); | |
| 47 data[length++] = c; | |
| 48 } | |
| 49 | |
| 50 void append(UChar32 c) | |
| 51 { | |
| 52 if (U_IS_BMP(c)) { | |
| 53 append(static_cast<UChar>(c)); | |
| 54 return; | |
| 55 } | |
| 56 append(U16_LEAD(c)); | |
| 57 append(U16_TRAIL(c)); | |
| 58 } | |
| 59 | |
| 60 unsigned length; | |
| 61 UChar data[kMaxLength]; | |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 bool consumeHTMLEntity(SegmentedString&, DecodedHTMLEntity& decodedEntity, bool&
notEnoughCharacters, UChar additionalAllowedCharacter = '\0'); | |
| 65 | |
| 66 // Used by the XML parser. Not suitable for use in HTML parsing. Use consumeHT
MLEntity instead. | |
| 67 size_t decodeNamedEntityToUCharArray(const char*, UChar result[4]); | |
| 68 | |
| 69 } | 64 } |
| 70 | 65 |
| 71 #endif | 66 #endif |
| OLD | NEW |