Exemple #1
0
 static size_t PrevCharLength(const char* str) {
   for (size_t i = 1; i <= 6; i++) {
     str--;
     size_t length = NextCharLength(str);
     if (length == i) {
       return length;
     }
   }
   // Invalid UTF8 string or in the middle of a UTF8 char
   return 0;
 }
Exemple #2
0
 static string TruncateUTF8(const char* str, size_t maxLength) {
   string wordTrunc;
   if (NotShorterThan(str, maxLength)) {
     size_t len = 0;
     const char* pStr = str;
     while (len < maxLength) {
       size_t nextLen = NextCharLength(pStr);
       pStr += nextLen;
       len += nextLen;
     }
     wordTrunc = FromSubstr(str, len);
   } else {
     wordTrunc = str;
   }
   return wordTrunc;
 }
Exemple #3
0
 /**
 * Truncates a string with a maximal length in byte.
 * No UTF8 character will be broken.
 */
 static string TruncateUTF8(const char* str, size_t maxByteLength) {
     string wordTrunc;
     if (NotShorterThan(str, maxByteLength)) {
         size_t len = 0;
         const char* pStr = str;
         for (;;) {
             const size_t charLength = NextCharLength(pStr);
             if (len + charLength > maxByteLength) {
                 break;
             }
             pStr += charLength;
             len += charLength;
         }
         wordTrunc = FromSubstr(str, len);
     } else {
         wordTrunc = str;
     }
     return wordTrunc;
 }
Exemple #4
0
 /**
 * Returns the char* pointer over the next UTF8 character.
 */
 static const char* NextChar(const char* str) {
     return str + NextCharLength(str);
 }