Fix action icons in the log dialog being clipped on High-DPI displays
[TortoiseGit.git] / ext / scintilla / src / UniConversion.h
blob780d08ab581810f27de5a3c9148666fac7d7e792
1 // Scintilla source code edit control
2 /** @file UniConversion.h
3 ** Functions to handle UTF-8 and UTF-16 strings.
4 **/
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
8 #ifndef UNICONVERSION_H
9 #define UNICONVERSION_H
11 #ifdef SCI_NAMESPACE
12 namespace Scintilla {
13 #endif
15 const int UTF8MaxBytes = 4;
17 const int unicodeReplacementChar = 0xFFFD;
19 unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen);
20 void UTF8FromUTF16(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len);
21 unsigned int UTF8CharLength(unsigned char ch);
22 size_t UTF16Length(const char *s, size_t len);
23 size_t UTF16FromUTF8(const char *s, size_t len, wchar_t *tbuf, size_t tlen);
24 unsigned int UTF32FromUTF8(const char *s, unsigned int len, unsigned int *tbuf, unsigned int tlen);
25 unsigned int UTF16FromUTF32Character(unsigned int val, wchar_t *tbuf);
26 std::string FixInvalidUTF8(const std::string &text);
28 extern int UTF8BytesOfLead[256];
29 void UTF8BytesOfLeadInitialise();
31 inline bool UTF8IsTrailByte(int ch) {
32 return (ch >= 0x80) && (ch < 0xc0);
35 inline bool UTF8IsAscii(int ch) {
36 return ch < 0x80;
39 enum { UTF8MaskWidth=0x7, UTF8MaskInvalid=0x8 };
40 int UTF8Classify(const unsigned char *us, int len);
42 // Similar to UTF8Classify but returns a length of 1 for invalid bytes
43 // instead of setting the invalid flag
44 int UTF8DrawBytes(const unsigned char *us, int len);
46 // Line separator is U+2028 \xe2\x80\xa8
47 // Paragraph separator is U+2029 \xe2\x80\xa9
48 const int UTF8SeparatorLength = 3;
49 inline bool UTF8IsSeparator(const unsigned char *us) {
50 return (us[0] == 0xe2) && (us[1] == 0x80) && ((us[2] == 0xa8) || (us[2] == 0xa9));
53 // NEL is U+0085 \xc2\x85
54 const int UTF8NELLength = 2;
55 inline bool UTF8IsNEL(const unsigned char *us) {
56 return (us[0] == 0xc2) && (us[1] == 0x85);
59 enum { SURROGATE_LEAD_FIRST = 0xD800 };
60 enum { SURROGATE_LEAD_LAST = 0xDBFF };
61 enum { SURROGATE_TRAIL_FIRST = 0xDC00 };
62 enum { SURROGATE_TRAIL_LAST = 0xDFFF };
63 enum { SUPPLEMENTAL_PLANE_FIRST = 0x10000 };
65 inline unsigned int UTF16CharLength(wchar_t uch) {
66 return ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_LEAD_LAST)) ? 2 : 1;
69 #ifdef SCI_NAMESPACE
71 #endif
73 #endif