File: validateunicode.h

package info (click to toggle)
nsis 3.04-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,076 kB
  • sloc: cpp: 36,735; ansic: 26,691; python: 1,282; asm: 712; xml: 511; pascal: 215; makefile: 205
file content (62 lines) | stat: -rwxr-xr-x 1,700 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// validateunicode.h
//
// This file is a part of Unicode NSIS.
//
// Copyright (C) 2009-2018 Jim Park
//
// Licensed under the zlib/libpng license (the "License");
// you may not use this file except in compliance with the License.
//
// This software is provided 'as-is', without any expressed or implied
// warranty.
//
// This class can be used to check a buffer to see if it has the expected
// Unicode encoding and look for byte order marks.

#ifndef _VALIDATEUNICODE_
#define _VALIDATEUNICODE_

#include "tchar.h"
#include <stdio.h>

class CValidateUnicode
{
	public:

		// Enum type for each Unicode encoding.
		enum FILE_TYPE
		{
			UTF_8 = 0,
			UTF_16LE,
			UTF_16BE,
			UTF_32LE,
			UTF_32BE,
			UNKNOWN
		};

		// Make sure that the buffer contains valid UTF-8 encoding.
		static int ValidateUTF8(unsigned char* buf, size_t characters);

		// Make sure that the buffer contains valid UTF-16LE encoding.
		static bool ValidateUTF16LE(unsigned char* buf, size_t bytes);

		// Make sure that the buffer contains valid UTF-16BE encoding.
		static bool ValidateUTF16BE(unsigned char* buf, size_t bytes);

		// Make sure that the buffer contains valid UTF-16 encoding.
		static bool ValidateUTF16(unsigned short* buf, size_t characters);

		// Does the buffer have a byte order mark?  And if so, what does it say?
		static FILE_TYPE CheckBOM(unsigned char* buf, size_t bytes);

		// Convert a FILE_TYPE enum to a string.
		static const TCHAR* TypeToName(FILE_TYPE ftype);

	protected:

		// Given the initial byte of a UTF-8 character, how many bytes are to
		// follow?
		static int GetBytesToFollow(unsigned char ch);
};

#endif