Implemented BGA's UTF-8 char len suggestion in UTF8.h and used it in
BString::CountChars(). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1932 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -61,6 +61,15 @@ _IMPEXP_TEXTENCODING status_t convert_from_utf8(uint32 dstEncoding,
|
|||||||
int32 *state,
|
int32 *state,
|
||||||
char substitute = B_SUBSTITUTE);
|
char substitute = B_SUBSTITUTE);
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------*/
|
||||||
|
/*------- Utility Functions -----------------------------------*/
|
||||||
|
|
||||||
|
// Suggested by BGA
|
||||||
|
inline uint32 utf8_char_len(uchar c)
|
||||||
|
{
|
||||||
|
return (((0xE5000000 >> (((c) >> 3) & 0x1E)) & 3) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------*/
|
/*-------------------------------------------------------------*/
|
||||||
/*-------------------------------------------------------------*/
|
/*-------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
#include <Debug.h>
|
#include <Debug.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
#include <UTF8.h>
|
||||||
|
|
||||||
// Temporary Includes
|
// Temporary Includes
|
||||||
#include "string_helper.h"
|
#include "string_helper.h"
|
||||||
@@ -92,7 +93,9 @@ BString::CountChars() const
|
|||||||
count++;
|
count++;
|
||||||
|
|
||||||
// Jump to next UTF8 character
|
// Jump to next UTF8 character
|
||||||
for (; (*ptr & 0xc0) == 0x80; ptr++);
|
// for (; (*ptr & 0xc0) == 0x80; ptr++);
|
||||||
|
// ejaesler: BGA's nifty function
|
||||||
|
ptr += utf8_char_len(*ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
|
|||||||
Reference in New Issue
Block a user