2009-04-24 23:35:41 +00:00
|
|
|
// Scintilla source code edit control
|
|
|
|
/** @file UniConversion.h
|
2010-07-12 22:19:51 +00:00
|
|
|
** Functions to handle UTF-8 and UTF-16 strings.
|
2009-04-24 23:35:41 +00:00
|
|
|
**/
|
|
|
|
// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
// The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
const int UTF8MaxBytes = 4;
|
|
|
|
|
2009-04-24 23:35:41 +00:00
|
|
|
unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen);
|
|
|
|
void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len);
|
2010-07-12 22:19:51 +00:00
|
|
|
unsigned int UTF8CharLength(unsigned char ch);
|
2009-04-24 23:35:41 +00:00
|
|
|
unsigned int UTF16Length(const char *s, unsigned int len);
|
|
|
|
unsigned int UTF16FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen);
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
extern int UTF8BytesOfLead[256];
|
|
|
|
void UTF8BytesOfLeadInitialise();
|
|
|
|
|
|
|
|
inline bool UTF8IsTrailByte(int ch) {
|
|
|
|
return (ch >= 0x80) && (ch < 0xc0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool UTF8IsAscii(int ch) {
|
|
|
|
return ch < 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum { UTF8MaskWidth=0x7, UTF8MaskInvalid=0x8 };
|
|
|
|
int UTF8Classify(const unsigned char *us, int len);
|
|
|
|
|
|
|
|
// Line separator is U+2028 \xe2\x80\xa8
|
|
|
|
// Paragraph separator is U+2029 \xe2\x80\xa9
|
|
|
|
const int UTF8SeparatorLength = 3;
|
|
|
|
inline bool UTF8IsSeparator(const unsigned char *us) {
|
|
|
|
return (us[0] == 0xe2) && (us[1] == 0x80) && ((us[2] == 0xa8) || (us[2] == 0xa9));
|
|
|
|
}
|
|
|
|
|
|
|
|
// NEL is U+0085 \xc2\x85
|
|
|
|
const int UTF8NELLength = 2;
|
|
|
|
inline bool UTF8IsNEL(const unsigned char *us) {
|
|
|
|
return (us[0] == 0xc2) && (us[1] == 0x85);
|
|
|
|
}
|