| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2003, 2006, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2008 Holger Hans Peter Freyther | 3 * Copyright (C) 2008 Holger Hans Peter Freyther |
| 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 UTF16TextIterator::UTF16TextIterator(const UChar* characters, int currentCharact
er, int endOffset, int endCharacter) | 42 UTF16TextIterator::UTF16TextIterator(const UChar* characters, int currentCharact
er, int endOffset, int endCharacter) |
| 43 : m_characters(characters) | 43 : m_characters(characters) |
| 44 , m_charactersEnd(characters + (endCharacter - currentCharacter)) | 44 , m_charactersEnd(characters + (endCharacter - currentCharacter)) |
| 45 , m_offset(currentCharacter) | 45 , m_offset(currentCharacter) |
| 46 , m_endOffset(endOffset) | 46 , m_endOffset(endOffset) |
| 47 , m_currentGlyphLength(0) | 47 , m_currentGlyphLength(0) |
| 48 { | 48 { |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool UTF16TextIterator::consumeSurrogatePair(UChar32& character) | 51 bool UTF16TextIterator::isValidSurrogatePair(UChar32& character) |
| 52 { | 52 { |
| 53 if (!U16_IS_SURROGATE(character)) | |
| 54 return true; | |
| 55 | |
| 56 // If we have a surrogate pair, make sure it starts with the high part. | 53 // If we have a surrogate pair, make sure it starts with the high part. |
| 57 if (!U16_IS_SURROGATE_LEAD(character)) | 54 if (!U16_IS_SURROGATE_LEAD(character)) |
| 58 return false; | 55 return false; |
| 59 | 56 |
| 60 // Do we have a surrogate pair? If so, determine the full Unicode (32 bit) | 57 // Do we have a surrogate pair? If so, determine the full Unicode (32 bit) |
| 61 // code point before glyph lookup. | 58 // code point before glyph lookup. |
| 62 // Make sure we have another character and it's a low surrogate. | 59 // Make sure we have another character and it's a low surrogate. |
| 63 if (m_characters + 1 >= m_charactersEnd) | 60 if (m_characters + 1 >= m_charactersEnd) |
| 64 return false; | 61 return false; |
| 65 | 62 |
| 66 UChar low = m_characters[1]; | 63 UChar low = m_characters[1]; |
| 67 if (!U16_IS_TRAIL(low)) | 64 if (!U16_IS_TRAIL(low)) |
| 68 return false; | 65 return false; |
| 66 return true; |
| 67 } |
| 69 | 68 |
| 69 bool UTF16TextIterator::consumeSurrogatePair(UChar32& character) |
| 70 { |
| 71 if (!U16_IS_SURROGATE(character)) |
| 72 return true; |
| 73 |
| 74 if (!isValidSurrogatePair(character)) { |
| 75 character = replacementCharacter; |
| 76 return true; |
| 77 } |
| 78 |
| 79 UChar low = m_characters[1]; |
| 70 character = U16_GET_SUPPLEMENTARY(character, low); | 80 character = U16_GET_SUPPLEMENTARY(character, low); |
| 71 m_currentGlyphLength = 2; | 81 m_currentGlyphLength = 2; |
| 72 return true; | 82 return true; |
| 73 } | 83 } |
| 74 | 84 |
| 75 void UTF16TextIterator::consumeMultipleUChar() | 85 void UTF16TextIterator::consumeMultipleUChar() |
| 76 { | 86 { |
| 77 const UChar* markCharactersEnd = m_characters + m_currentGlyphLength; | 87 const UChar* markCharactersEnd = m_characters + m_currentGlyphLength; |
| 78 int markLength = m_currentGlyphLength; | 88 int markLength = m_currentGlyphLength; |
| 79 while (markCharactersEnd < m_charactersEnd) { | 89 while (markCharactersEnd < m_charactersEnd) { |
| 80 UChar32 nextCharacter; | 90 UChar32 nextCharacter; |
| 81 int nextCharacterLength = 0; | 91 int nextCharacterLength = 0; |
| 82 U16_NEXT(markCharactersEnd, nextCharacterLength, | 92 U16_NEXT(markCharactersEnd, nextCharacterLength, |
| 83 m_charactersEnd - markCharactersEnd, nextCharacter); | 93 m_charactersEnd - markCharactersEnd, nextCharacter); |
| 84 if (!(U_GET_GC_MASK(nextCharacter) & U_GC_M_MASK)) | 94 if (!(U_GET_GC_MASK(nextCharacter) & U_GC_M_MASK)) |
| 85 break; | 95 break; |
| 86 markLength += nextCharacterLength; | 96 markLength += nextCharacterLength; |
| 87 markCharactersEnd += nextCharacterLength; | 97 markCharactersEnd += nextCharacterLength; |
| 88 } | 98 } |
| 89 m_currentGlyphLength = markLength; | 99 m_currentGlyphLength = markLength; |
| 90 } | 100 } |
| 91 | 101 |
| 92 } | 102 } |
| OLD | NEW |