This source file includes following definitions.
- m_endCharacter
- consumeSlowCase
- normalizeVoicingMarks
#include "config.h"
#include "platform/text/SurrogatePairAwareTextIterator.h"
#include <unicode/unorm.h>
using namespace WTF;
using namespace Unicode;
namespace WebCore {
SurrogatePairAwareTextIterator::SurrogatePairAwareTextIterator(const UChar* characters, int currentCharacter, int lastCharacter, int endCharacter)
: m_characters(characters)
, m_currentCharacter(currentCharacter)
, m_lastCharacter(lastCharacter)
, m_endCharacter(endCharacter)
{
}
bool SurrogatePairAwareTextIterator::consumeSlowCase(UChar32& character, unsigned& clusterLength)
{
if (character <= 0x30FE) {
if (UChar32 normalized = normalizeVoicingMarks()) {
character = normalized;
clusterLength = 2;
}
return true;
}
if (!U16_IS_SURROGATE(character))
return true;
if (!U16_IS_SURROGATE_LEAD(character))
return false;
if (m_currentCharacter + 1 >= m_endCharacter)
return false;
UChar low = m_characters[1];
if (!U16_IS_TRAIL(low))
return false;
character = U16_GET_SUPPLEMENTARY(character, low);
clusterLength = 2;
return true;
}
UChar32 SurrogatePairAwareTextIterator::normalizeVoicingMarks()
{
static const uint8_t hiraganaKatakanaVoicingMarksCombiningClass = 8;
if (m_currentCharacter + 1 >= m_endCharacter)
return 0;
if (combiningClass(m_characters[1]) == hiraganaKatakanaVoicingMarksCombiningClass) {
UChar normalizedCharacters[2] = { 0, 0 };
UErrorCode uStatus = U_ZERO_ERROR;
int32_t resultLength = unorm_normalize(m_characters, 2, UNORM_NFC, UNORM_UNICODE_3_2, &normalizedCharacters[0], 2, &uStatus);
if (resultLength == 1 && !uStatus)
return normalizedCharacters[0];
}
return 0;
}
}