Debian Codegraph @

Source/validateunicode.h

raw
1 // validateunicode.h
2 //
3 // This file is a part of Unicode NSIS.
4 //
5 // Copyright (C) 2009-2026 Jim Park
6 //
7 // Licensed under the zlib/libpng license (the "License");
8 // you may not use this file except in compliance with the License.
9 //
10 // This software is provided 'as-is', without any expressed or implied
11 // warranty.
12 //
13 // This class can be used to check a buffer to see if it has the expected
14 // Unicode encoding and look for byte order marks.
15
16 #ifndef _VALIDATEUNICODE_
17 #define _VALIDATEUNICODE_
18
19 #include "tchar.h"
20 #include <stdio.h>
21
22 class CValidateUnicode
23 {
24 public:
25
26 // Enum type for each Unicode encoding.
27 enum FILE_TYPE
28 {
29 UTF_8 = 0,
30 UTF_16LE,
31 UTF_16BE,
32 UTF_32LE,
33 UTF_32BE,
34 UNKNOWN
35 };
36
37 // Make sure that the buffer contains valid UTF-8 encoding.
38 static int ValidateUTF8(unsigned char* buf, size_t characters);
39
40 // Make sure that the buffer contains valid UTF-16LE encoding.
41 static bool ValidateUTF16LE(unsigned char* buf, size_t bytes);
42
43 // Make sure that the buffer contains valid UTF-16BE encoding.
44 static bool ValidateUTF16BE(unsigned char* buf, size_t bytes);
45
46 // Make sure that the buffer contains valid UTF-16 encoding.
47 static bool ValidateUTF16(unsigned short* buf, size_t characters);
48
49 // Does the buffer have a byte order mark? And if so, what does it say?
50 static FILE_TYPE CheckBOM(unsigned char* buf, size_t bytes);
51
52 // Convert a FILE_TYPE enum to a string.
53 static const TCHAR* TypeToName(FILE_TYPE ftype);
54
55 protected:
56
57 // Given the initial byte of a UTF-8 character, how many bytes are to
58 // follow?
59 static int GetBytesToFollow(unsigned char ch);
60 };
61
62 #endif