static void TestCharLength() { static const uint32_t codepoint[]={ 1, 0x0061, 1, 0x007f, 2, 0x016f, 2, 0x07ff, 3, 0x0865, 3, 0x20ac, 4, 0x20402, 4, 0x23456, 4, 0x24506, 4, 0x20402, 4, 0x10402, 3, 0xd7ff, 3, 0xe000, }; int16_t i; UBool multiple; for(i=0; i<sizeof(codepoint)/sizeof(codepoint[0]); i=(int16_t)(i+2)){ UChar32 c=codepoint[i+1]; if(UTF8_CHAR_LENGTH(c) != (uint16_t)codepoint[i] || U8_LENGTH(c) != (uint16_t)codepoint[i]){ log_err("The no: of code units for %lx:- Expected: %d Got: %d\n", c, codepoint[i], UTF8_CHAR_LENGTH(c)); }else{ log_verbose("The no: of code units for %lx is %d\n",c, UTF8_CHAR_LENGTH(c) ); } multiple=(UBool)(codepoint[i] == 1 ? FALSE : TRUE); if(UTF8_NEED_MULTIPLE_UCHAR(c) != multiple){ log_err("ERROR: UTF8_NEED_MULTIPLE_UCHAR failed for %lx\n", c); } } }
int UString::getUnicodeFromIterator() { char* str = utf_data+iter; if(!(*str)){ iter = 0; return -1; } int ch = UTF8_GET_CHAR(str); if (!ch){ iter = 0; return -1; } iter += UTF8_CHAR_LENGTH(ch); return ch; }
int UString::getUnicodeFromIterator() { char* str = m_mallocBuffer+m_iter; if(!(*str)){ m_iter = 0; return -1; } int ch = UTF8_GET_CHAR(str); if (!ch){ m_iter = 0; return -1; } m_iter += UTF8_CHAR_LENGTH(ch); return ch; }
int UString::get(size_t index) const { char* str = utf_data; if(!str_len){ return -1; } while (index > 0){ int ch = UTF8_GET_CHAR(str); if (!ch){ return -1; } str += UTF8_CHAR_LENGTH(ch); index--; } return UTF8_GET_CHAR(str); }
int UString::get(size_t index) const { char* str = m_mallocBuffer; if(!m_strLen){ return -1; } while (index > 0){ int ch = UTF8_GET_CHAR(str); if (!ch){ return -1; } str += UTF8_CHAR_LENGTH(ch); index--; } return UTF8_GET_CHAR(str); }