本文整理汇总了C++中U16_IS_LEAD函数的典型用法代码示例。如果您正苦于以下问题:C++ U16_IS_LEAD函数的具体用法?C++ U16_IS_LEAD怎么用?C++ U16_IS_LEAD使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了U16_IS_LEAD函数的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: fillGlyphPage
bool SimpleFontData::fillGlyphPage(GlyphPage* pageToFill,
unsigned offset,
unsigned length,
UChar* buffer,
unsigned bufferLength) const {
if (U16_IS_LEAD(buffer[bufferLength - 1])) {
SkDebugf("%s last char is high-surrogate", __FUNCTION__);
return false;
}
SkAutoSTMalloc<GlyphPage::size, uint16_t> glyphStorage(length);
uint16_t* glyphs = glyphStorage.get();
SkTypeface* typeface = platformData().typeface();
typeface->charsToGlyphs(buffer, SkTypeface::kUTF16_Encoding, glyphs, length);
bool haveGlyphs = false;
for (unsigned i = 0; i < length; i++) {
if (glyphs[i]) {
pageToFill->setGlyphDataForIndex(offset + i, glyphs[i], this);
haveGlyphs = true;
}
}
return haveGlyphs;
}
示例7:
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;
}
示例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: 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();
}
示例10: 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;
}
示例11: if
UChar32
FCDUIterCollationIterator::previousCodePoint(UErrorCode &errorCode) {
UChar32 c;
for(;;) {
if(state == ITER_CHECK_BWD) {
c = iter.previous(&iter);
if(c < 0) {
start = pos = 0;
state = ITER_IN_FCD_SEGMENT;
return U_SENTINEL;
}
if(CollationFCD::hasLccc(c)) {
UChar32 prev = U_SENTINEL;
if(CollationFCD::maybeTibetanCompositeVowel(c) ||
CollationFCD::hasTccc(prev = iter.previous(&iter))) {
iter.next(&iter);
if(prev >= 0) {
iter.next(&iter);
}
if(!previousSegment(errorCode)) {
return U_SENTINEL;
}
continue;
}
// hasLccc(trail)=true for all trail surrogates
if(U16_IS_TRAIL(c)) {
if(prev < 0) {
prev = iter.previous(&iter);
}
if(U16_IS_LEAD(prev)) {
return U16_GET_SUPPLEMENTARY(prev, c);
}
}
if(prev >= 0) {
iter.next(&iter);
}
}
return c;
} else if(state == ITER_IN_FCD_SEGMENT && pos != start) {
c = uiter_previous32(&iter);
pos -= U16_LENGTH(c);
U_ASSERT(c >= 0);
return c;
} else if(state >= IN_NORM_ITER_AT_LIMIT && pos != 0) {
c = normalized.char32At(pos - 1);
pos -= U16_LENGTH(c);
return c;
} else {
switchToBackward();
}
}
}
示例12: IsUtf16StringValid
//
// Check if a UTF16 string is valid according to the UTF16 standard
// Specifically, check that we don't have any invalid surrogate pairs
// If the string is valid, we return true.
// If not, we set invalidIndex to the index of the first invalid char index
// and return false
// If the invalid char is a lead surrogate pair, we return its index
// Otherwise, we treat the char before as the invalid one and return index - 1
// This function has defined behavior only for null-terminated strings.
// If the string is not null terminated, the behavior is undefined (likely hang)
//
static bool IsUtf16StringValid(const UChar* str, size_t length, size_t* invalidIndex)
{
Assert(invalidIndex != nullptr);
*invalidIndex = -1;
size_t i = 0;
for (;;)
{
// Iterate through the UTF16-LE string
// If we are at the end of the null terminated string, return true
// since the string is valid
// If not, check if the codepoint we have is a surrogate code unit.
// If it is, the string is malformed since U16_NEXT would have returned
// is the full codepoint if both code units in the surrogate pair were present
UChar32 c;
U16_NEXT(str, i, length, c);
if (c == 0)
{
return true;
}
if (U_IS_SURROGATE(c))
{
if (U16_IS_LEAD(c))
{
*invalidIndex = i;
}
else
{
Assert(i > 0);
*invalidIndex = i - 1;
}
return false;
}
if (i >= length)
{
return true;
}
}
}
示例13: sanitizeUserInputValue
String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue,
unsigned maxLength) {
unsigned submissionLength = 0;
unsigned i = 0;
for (; i < proposedValue.length(); ++i) {
if (proposedValue[i] == '\r' && i + 1 < proposedValue.length() &&
proposedValue[i + 1] == '\n')
continue;
++submissionLength;
if (submissionLength == maxLength) {
++i;
break;
}
if (submissionLength > maxLength)
break;
}
if (i > 0 && U16_IS_LEAD(proposedValue[i - 1]))
--i;
return proposedValue.left(i);
}
示例14: setOffset
void CollationElementIterator::setOffset(int32_t newOffset,
UErrorCode& status)
{
if (U_FAILURE(status)) { return; }
if (0 < newOffset && newOffset < string_.length()) {
int32_t offset = newOffset;
do {
UChar c = string_.charAt(offset);
if (!rbc_->isUnsafe(c) ||
(U16_IS_LEAD(c) && !rbc_->isUnsafe(string_.char32At(offset)))) {
break;
}
// Back up to before this unsafe character.
--offset;
} while (offset > 0);
if (offset < newOffset) {
// We might have backed up more than necessary.
// For example, contractions "ch" and "cu" make both 'h' and 'u' unsafe,
// but for text "chu" setOffset(2) should remain at 2
// although we initially back up to offset 0.
// Find the last safe offset no greater than newOffset by iterating forward.
int32_t lastSafeOffset = offset;
do {
iter_->resetToOffset(lastSafeOffset);
do {
iter_->nextCE(status);
if (U_FAILURE(status)) { return; }
} while ((offset = iter_->getOffset()) == lastSafeOffset);
if (offset <= newOffset) {
lastSafeOffset = offset;
}
} while (offset < newOffset);
newOffset = lastSafeOffset;
}
}
iter_->resetToOffset(newOffset);
otherHalf_ = 0;
dir_ = 1;
}
示例15: ucbuf_getc32
/* get a UChar32 from the stream*/
U_CAPI int32_t U_EXPORT2
ucbuf_getc32(UCHARBUF* buf,UErrorCode* error){
int32_t retVal = (int32_t)U_EOF;
if(error==NULL || U_FAILURE(*error)){
return FALSE;
}
if(buf->currentPos+1>=buf->bufLimit){
if(buf->remaining==0){
return U_EOF;
}
buf=ucbuf_fillucbuf(buf,error);
if(U_FAILURE(*error)){
return U_EOF;
}
}
if(U16_IS_LEAD(*(buf->currentPos))){
retVal=U16_GET_SUPPLEMENTARY(buf->currentPos[0],buf->currentPos[1]);
buf->currentPos+=2;
}else{
retVal = *(buf->currentPos++);
}
return retVal;
}