本文整理汇总了C++中U16_IS_TRAIL函数的典型用法代码示例。如果您正苦于以下问题:C++ U16_IS_TRAIL函数的具体用法?C++ U16_IS_TRAIL怎么用?C++ U16_IS_TRAIL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了U16_IS_TRAIL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: u_strCompareIter
/*
* Compare two strings as presented by UCharIterators.
* Use code unit or code point order.
* When the function returns, it is undefined where the iterators
* have stopped.
*/
U_CAPI int32_t U_EXPORT2
u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder) {
UChar32 c1, c2;
/* argument checking */
if(iter1==NULL || iter2==NULL) {
return 0; /* bad arguments */
}
if(iter1==iter2) {
return 0; /* identical iterators */
}
/* reset iterators to start? */
iter1->move(iter1, 0, UITER_START);
iter2->move(iter2, 0, UITER_START);
/* compare identical prefixes - they do not need to be fixed up */
for(;;) {
c1=iter1->next(iter1);
c2=iter2->next(iter2);
if(c1!=c2) {
break;
}
if(c1==-1) {
return 0;
}
}
/* if both values are in or above the surrogate range, fix them up */
if(c1>=0xd800 && c2>=0xd800 && codePointOrder) {
/* subtract 0x2800 from BMP code points to make them smaller than supplementary ones */
if(
(c1<=0xdbff && U16_IS_TRAIL(iter1->current(iter1))) ||
(U16_IS_TRAIL(c1) && (iter1->previous(iter1), U16_IS_LEAD(iter1->previous(iter1))))
) {
/* part of a surrogate pair, leave >=d800 */
} else {
/* BMP code point - may be surrogate code point - make <d800 */
c1-=0x2800;
}
if(
(c2<=0xdbff && U16_IS_TRAIL(iter2->current(iter2))) ||
(U16_IS_TRAIL(c2) && (iter2->previous(iter2), U16_IS_LEAD(iter2->previous(iter2))))
) {
/* part of a surrogate pair, leave >=d800 */
} else {
/* BMP code point - may be surrogate code point - make <d800 */
c2-=0x2800;
}
}
/* now c1 and c2 are in the requested (code unit or code point) order */
return (int32_t)c1-(int32_t)c2;
}
示例2: isMatchAtCPBoundary
/*
* Test if a substring match inside a string is at code point boundaries.
* All pointers refer to the same buffer.
* The limit pointer may be NULL, all others must be real pointers.
*/
static U_INLINE UBool
isMatchAtCPBoundary(const UChar* start, const UChar* match, const UChar* matchLimit, const UChar* limit) {
if (U16_IS_TRAIL(*match) && start != match && U16_IS_LEAD(*(match - 1))) {
/* the leading edge of the match is in the middle of a surrogate pair */
return FALSE;
}
if (U16_IS_LEAD(*(matchLimit - 1)) && match != limit && U16_IS_TRAIL(*matchLimit)) {
/* the trailing edge of the match is in the middle of a surrogate pair */
return FALSE;
}
return TRUE;
}
示例3: canExpandAroundIdeographsInComplexText
unsigned Font::expansionOpportunityCount(const UChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion)
{
static bool expandAroundIdeographs = canExpandAroundIdeographsInComplexText();
unsigned count = 0;
if (direction == LTR) {
for (size_t i = 0; i < length; ++i) {
UChar32 character = characters[i];
if (treatAsSpace(character)) {
count++;
isAfterExpansion = true;
continue;
}
if (U16_IS_LEAD(character) && i + 1 < length && U16_IS_TRAIL(characters[i + 1])) {
character = U16_GET_SUPPLEMENTARY(character, characters[i + 1]);
i++;
}
if (expandAroundIdeographs && isCJKIdeographOrSymbol(character)) {
if (!isAfterExpansion)
count++;
count++;
isAfterExpansion = true;
continue;
}
isAfterExpansion = false;
}
} else {
for (size_t i = length; i > 0; --i) {
UChar32 character = characters[i - 1];
if (treatAsSpace(character)) {
count++;
isAfterExpansion = true;
continue;
}
if (U16_IS_TRAIL(character) && i > 1 && U16_IS_LEAD(characters[i - 2])) {
character = U16_GET_SUPPLEMENTARY(characters[i - 2], character);
i--;
}
if (expandAroundIdeographs && isCJKIdeographOrSymbol(character)) {
if (!isAfterExpansion)
count++;
count++;
isAfterExpansion = true;
continue;
}
isAfterExpansion = false;
}
}
return count;
}
示例4: U16_GET_SUPPLEMENTARY
unsigned Character::expansionOpportunityCount(const UChar* characters, size_t length, TextDirection direction, bool& isAfterExpansion, const TextJustify textJustify)
{
unsigned count = 0;
if (direction == LTR) {
for (size_t i = 0; i < length; ++i) {
UChar32 character = characters[i];
if (treatAsSpace(character)) {
count++;
isAfterExpansion = true;
continue;
}
if (U16_IS_LEAD(character) && i + 1 < length && U16_IS_TRAIL(characters[i + 1])) {
character = U16_GET_SUPPLEMENTARY(character, characters[i + 1]);
i++;
}
if (textJustify == TextJustify::TextJustifyAuto && isCJKIdeographOrSymbol(character)) {
if (!isAfterExpansion)
count++;
count++;
isAfterExpansion = true;
continue;
}
isAfterExpansion = false;
}
} else {
for (size_t i = length; i > 0; --i) {
UChar32 character = characters[i - 1];
if (treatAsSpace(character)) {
count++;
isAfterExpansion = true;
continue;
}
if (U16_IS_TRAIL(character) && i > 1 && U16_IS_LEAD(characters[i - 2])) {
character = U16_GET_SUPPLEMENTARY(characters[i - 2], character);
i--;
}
if (textJustify == TextJustify::TextJustifyAuto && isCJKIdeographOrSymbol(character)) {
if (!isAfterExpansion)
count++;
count++;
isAfterExpansion = true;
continue;
}
isAfterExpansion = false;
}
}
return count;
}
示例5: TestCodeUnitValues
static void TestCodeUnitValues()
{
static uint16_t codeunit[]={0x0000,0xe065,0x20ac,0xd7ff,0xd800,0xd841,0xd905,0xdbff,0xdc00,0xdc02,0xddee,0xdfff,0};
int16_t i;
for(i=0; i<sizeof(codeunit)/sizeof(codeunit[0]); i++){
UChar c=codeunit[i];
log_verbose("Testing code unit value of %x\n", c);
if(i<4){
if(!UTF16_IS_SINGLE(c) || UTF16_IS_LEAD(c) || UTF16_IS_TRAIL(c) || !U16_IS_SINGLE(c) || U16_IS_LEAD(c) || U16_IS_TRAIL(c)){
log_err("ERROR: %x is a single character\n", c);
}
}
if(i >= 4 && i< 8){
if(!UTF16_IS_LEAD(c) || UTF16_IS_SINGLE(c) || UTF16_IS_TRAIL(c) || !U16_IS_LEAD(c) || U16_IS_SINGLE(c) || U16_IS_TRAIL(c)){
log_err("ERROR: %x is a first surrogate\n", c);
}
}
if(i >= 8 && i< 12){
if(!UTF16_IS_TRAIL(c) || UTF16_IS_SINGLE(c) || UTF16_IS_LEAD(c) || !U16_IS_TRAIL(c) || U16_IS_SINGLE(c) || U16_IS_LEAD(c)){
log_err("ERROR: %x is a second surrogate\n", c);
}
}
}
}
示例6:
void
MessagePattern::setParseError(UParseError *parseError, int32_t index) {
if(parseError==NULL) {
return;
}
parseError->offset=index;
// Set preContext to some of msg before index.
// Avoid splitting a surrogate pair.
int32_t length=index;
if(length>=U_PARSE_CONTEXT_LEN) {
length=U_PARSE_CONTEXT_LEN-1;
if(length>0 && U16_IS_TRAIL(msg[index-length])) {
--length;
}
}
msg.extract(index-length, length, parseError->preContext);
parseError->preContext[length]=0;
// Set postContext to some of msg starting at index.
length=msg.length()-index;
if(length>=U_PARSE_CONTEXT_LEN) {
length=U_PARSE_CONTEXT_LEN-1;
if(length>0 && U16_IS_LEAD(msg[index+length-1])) {
--length;
}
}
msg.extract(index, length, parseError->postContext);
parseError->postContext[length]=0;
}
示例7: if
UChar
FCDUIterCollationIterator::handleGetTrailSurrogate() {
if(state <= ITER_IN_FCD_SEGMENT) {
UChar32 trail = iter.next(&iter);
if(U16_IS_TRAIL(trail)) {
if(state == ITER_IN_FCD_SEGMENT) { ++pos; }
} else if(trail >= 0) {
iter.previous(&iter);
}
return (UChar)trail;
} else {
U_ASSERT(pos < normalized.length());
UChar trail;
if(U16_IS_TRAIL(trail = normalized[pos])) { ++pos; }
return trail;
}
}
示例8: characterStartingAt
UChar32 StringImpl::characterStartingAt(unsigned i)
{
if (U16_IS_SINGLE(m_data[i]))
return m_data[i];
if (i + 1 < m_length && U16_IS_LEAD(m_data[i]) && U16_IS_TRAIL(m_data[i + 1]))
return U16_GET_SUPPLEMENTARY(m_data[i], m_data[i + 1]);
return 0;
}
示例9: U_ASSERT
UChar
FCDUTF8CollationIterator::handleGetTrailSurrogate() {
if(state != IN_NORMALIZED) { return 0; }
U_ASSERT(pos < normalized.length());
UChar trail;
if(U16_IS_TRAIL(trail = normalized[pos])) { ++pos; }
return trail;
}
示例10: nextExpansion
float ShapeResultSpacing::computeSpacing(const TextRun& run,
size_t index,
float& offset) {
UChar32 character = run[index];
bool treatAsSpace =
(Character::treatAsSpace(character) ||
(m_normalizeSpace &&
Character::isNormalizedCanvasSpaceCharacter(character))) &&
(character != '\t' || !m_allowTabs);
if (treatAsSpace && character != noBreakSpaceCharacter)
character = spaceCharacter;
float spacing = 0;
if (m_letterSpacing && !Character::treatAsZeroWidthSpace(character))
spacing += m_letterSpacing;
if (treatAsSpace &&
(index || !isFirstRun(run) || character == noBreakSpaceCharacter))
spacing += m_wordSpacing;
if (!hasExpansion())
return spacing;
if (treatAsSpace)
return spacing + nextExpansion();
if (run.is8Bit() || m_textJustify != TextJustify::TextJustifyAuto)
return spacing;
// isCJKIdeographOrSymbol() has expansion opportunities both before and
// after each character.
// http://www.w3.org/TR/jlreq/#line_adjustment
if (U16_IS_LEAD(character) && index + 1 < run.length() &&
U16_IS_TRAIL(run[index + 1]))
character = U16_GET_SUPPLEMENTARY(character, run[index + 1]);
if (!Character::isCJKIdeographOrSymbol(character)) {
m_isAfterExpansion = false;
return spacing;
}
if (!m_isAfterExpansion) {
// Take the expansion opportunity before this ideograph.
float expandBefore = nextExpansion();
if (expandBefore) {
offset += expandBefore;
spacing += expandBefore;
}
if (!hasExpansion())
return spacing;
}
return spacing + nextExpansion();
}
示例11: u_countChar32
U_CAPI int32_t U_EXPORT2
u_countChar32(const UChar *s, int32_t length) {
int32_t count;
if(s==NULL || length<-1) {
return 0;
}
count=0;
if(length>=0) {
while(length>0) {
++count;
if(U16_IS_LEAD(*s) && length>=2 && U16_IS_TRAIL(*(s+1))) {
s+=2;
length-=2;
} else {
++s;
--length;
}
}
} else /* length==-1 */ {
UChar c;
for(;;) {
if((c=*s++)==0) {
break;
}
++count;
/*
* sufficient to look ahead one because of UTF-16;
* safe to look ahead one because at worst that would be the terminating NUL
*/
if(U16_IS_LEAD(c) && U16_IS_TRAIL(*s)) {
++s;
}
}
}
return count;
}
示例12:
bool UTF16TextIterator::isValidSurrogatePair(UChar32& character)
{
// If we have a surrogate pair, make sure it starts with the high part.
if (!U16_IS_SURROGATE_LEAD(character))
return false;
// Do we have a surrogate pair? If so, determine the full Unicode (32 bit)
// code point before glyph lookup.
// Make sure we have another character and it's a low surrogate.
if (m_characters + 1 >= m_charactersEnd)
return false;
UChar low = m_characters[1];
if (!U16_IS_TRAIL(low))
return false;
return true;
}
示例13: createFontConfigPatternForCharacters
FcPattern* createFontConfigPatternForCharacters(const UChar* characters, int length)
{
FcPattern* pattern = FcPatternCreate();
FcCharSet* fontConfigCharSet = FcCharSetCreate();
for (int i = 0; i < length; ++i) {
if (U16_IS_SURROGATE(characters[i]) && U16_IS_SURROGATE_LEAD(characters[i])
&& i != length - 1 && U16_IS_TRAIL(characters[i + 1])) {
FcCharSetAddChar(fontConfigCharSet, U16_GET_SUPPLEMENTARY(characters[i], characters[i+1]));
i++;
} else
FcCharSetAddChar(fontConfigCharSet, characters[i]);
}
FcPatternAddCharSet(pattern, FC_CHARSET, fontConfigCharSet);
FcCharSetDestroy(fontConfigCharSet);
FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
FcConfigSubstitute(0, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
return pattern;
}
示例14: readUTFChar
bool readUTFChar(const UChar* str, int* begin, int length, unsigned* codePoint)
{
if (U16_IS_SURROGATE(str[*begin])) {
if (!U16_IS_SURROGATE_LEAD(str[*begin]) || *begin + 1 >= length || !U16_IS_TRAIL(str[*begin + 1])) {
// Invalid surrogate pair.
*codePoint = kUnicodeReplacementCharacter;
return false;
}
// Valid surrogate pair.
*codePoint = U16_GET_SUPPLEMENTARY(str[*begin], str[*begin + 1]);
(*begin)++;
} else {
// Not a surrogate, just one 16-bit word.
*codePoint = str[*begin];
}
if (U_IS_UNICODE_CHAR(*codePoint))
return true;
// Invalid code point.
*codePoint = kUnicodeReplacementCharacter;
return false;
}
示例15: getEmphasisMarkGlyphData
// FIXME: This function may not work if the emphasis mark uses a complex script, but none of the
// standard emphasis marks do so.
bool Font::getEmphasisMarkGlyphData(const AtomicString& mark, GlyphData& glyphData) const
{
if (mark.isEmpty())
return false;
UChar32 character = mark[0];
if (U16_IS_SURROGATE(character)) {
if (!U16_IS_SURROGATE_LEAD(character))
return false;
if (mark.length() < 2)
return false;
UChar low = mark[1];
if (!U16_IS_TRAIL(low))
return false;
character = U16_GET_SUPPLEMENTARY(character, low);
}
glyphData = glyphDataForCharacter(character, false, EmphasisMarkVariant);
return true;
}