* Removed my custom String class, as well as removed the really old
Unicode ConvertUTF, the UTF Converter, and the UTF Encode/Decode
functions.
* Replaced the above with using standard C++ std::wstring_convert and
std::codecvt_utf8.
* Added headers adapted from llvm's libc++ project for allowing the
above C++ classes to exist with GCC and Clang when libc++ isn't being
used.
* Used std::string over std::wstring whenever possible.
* Added header adapted from llvm's libc++ project to create special
versions of the ifstream and ofstream classes that would utilize _wfopen
on non-MSVC Windows compilers, so those compilers could access files on
Windows that use characters outside the current codepage.
* Removed the -static-libgcc and -static-libstdc++ flags from the
Makefile for non-MSVC builds. The generated DLLs will require extra DLLs
from either Cygwin or MinGW (whichever is used to compile), I've only
tested with MinGW and for some reason they crash Winamp on exit, I have
no idea why.
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,131 +0,0 @@ |
| 1 |
-/* |
|
| 2 |
- * Copyright 2001-2004 Unicode, Inc. |
|
| 3 |
- * |
|
| 4 |
- * Disclaimer |
|
| 5 |
- * |
|
| 6 |
- * This source code is provided as is by Unicode, Inc. No claims are |
|
| 7 |
- * made as to fitness for any particular purpose. No warranties of any |
|
| 8 |
- * kind are expressed or implied. The recipient agrees to determine |
|
| 9 |
- * applicability of information provided. If this file has been |
|
| 10 |
- * purchased on magnetic or optical media from Unicode, Inc., the |
|
| 11 |
- * sole remedy for any claim will be exchange of defective media |
|
| 12 |
- * within 90 days of receipt. |
|
| 13 |
- * |
|
| 14 |
- * Limitations on Rights to Redistribute This Code |
|
| 15 |
- * |
|
| 16 |
- * Unicode, Inc. hereby grants the right to freely use the information |
|
| 17 |
- * supplied in this file in the creation of products supporting the |
|
| 18 |
- * Unicode Standard, and to make copies of this file in any form |
|
| 19 |
- * for internal or external distribution as long as this notice |
|
| 20 |
- * remains attached. |
|
| 21 |
- */ |
|
| 22 |
- |
|
| 23 |
-/* --------------------------------------------------------------------- |
|
| 24 |
- |
|
| 25 |
- Conversions between UTF32, UTF-16, and UTF-8. Header file. |
|
| 26 |
- |
|
| 27 |
- Several funtions are included here, forming a complete set of |
|
| 28 |
- conversions between the three formats. UTF-7 is not included |
|
| 29 |
- here, but is handled in a separate source file. |
|
| 30 |
- |
|
| 31 |
- Each of these routines takes pointers to input buffers and output |
|
| 32 |
- buffers. The input buffers are const. |
|
| 33 |
- |
|
| 34 |
- Each routine converts the text between *sourceStart and sourceEnd, |
|
| 35 |
- putting the result into the buffer between *targetStart and |
|
| 36 |
- targetEnd. Note: the end pointers are *after* the last item: e.g. |
|
| 37 |
- *(sourceEnd - 1) is the last item. |
|
| 38 |
- |
|
| 39 |
- The return result indicates whether the conversion was successful, |
|
| 40 |
- and if not, whether the problem was in the source or target buffers. |
|
| 41 |
- (Only the first encountered problem is indicated.) |
|
| 42 |
- |
|
| 43 |
- After the conversion, *sourceStart and *targetStart are both |
|
| 44 |
- updated to point to the end of last text successfully converted in |
|
| 45 |
- the respective buffers. |
|
| 46 |
- |
|
| 47 |
- Input parameters: |
|
| 48 |
- sourceStart - pointer to a pointer to the source buffer. |
|
| 49 |
- The contents of this are modified on return so that |
|
| 50 |
- it points at the next thing to be converted. |
|
| 51 |
- targetStart - similarly, pointer to pointer to the target buffer. |
|
| 52 |
- sourceEnd, targetEnd - respectively pointers to the ends of the |
|
| 53 |
- two buffers, for overflow checking only. |
|
| 54 |
- |
|
| 55 |
- These conversion functions take a ConversionFlags argument. When this |
|
| 56 |
- flag is set to strict, both irregular sequences and isolated surrogates |
|
| 57 |
- will cause an error. When the flag is set to lenient, both irregular |
|
| 58 |
- sequences and isolated surrogates are converted. |
|
| 59 |
- |
|
| 60 |
- Whether the flag is strict or lenient, all illegal sequences will cause |
|
| 61 |
- an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>, |
|
| 62 |
- or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code |
|
| 63 |
- must check for illegal sequences. |
|
| 64 |
- |
|
| 65 |
- When the flag is set to lenient, characters over 0x10FFFF are converted |
|
| 66 |
- to the replacement character; otherwise (when the flag is set to strict) |
|
| 67 |
- they constitute an error. |
|
| 68 |
- |
|
| 69 |
- Output parameters: |
|
| 70 |
- The value "sourceIllegal" is returned from some routines if the input |
|
| 71 |
- sequence is malformed. When "sourceIllegal" is returned, the source |
|
| 72 |
- value will point to the illegal value that caused the problem. E.g., |
|
| 73 |
- in UTF-8 when a sequence is malformed, it points to the start of the |
|
| 74 |
- malformed sequence. |
|
| 75 |
- |
|
| 76 |
- Author: Mark E. Davis, 1994. |
|
| 77 |
- Rev History: Rick McGowan, fixes & updates May 2001. |
|
| 78 |
- Fixes & updates, Sept 2001. |
|
| 79 |
- |
|
| 80 |
- |
|
| 81 |
-#pragma once |
|
| 82 |
- |
|
| 83 |
-/* --------------------------------------------------------------------- |
|
| 84 |
- The following 4 definitions are compiler-specific. |
|
| 85 |
- The C standard does not guarantee that wchar_t has at least |
|
| 86 |
- 16 bits, so wchar_t is no less portable than unsigned short! |
|
| 87 |
- All should be unsigned values to avoid sign extension during |
|
| 88 |
- bit mask & shift operations. |
|
| 89 |
- |
|
| 90 |
-typedef unsigned long UTF32; /* at least 32 bits */ |
|
| 91 |
-typedef unsigned short UTF16; /* at least 16 bits */ |
|
| 92 |
-typedef unsigned char UTF8; /* typically 8 bits */ |
|
| 93 |
- |
|
| 94 |
-/* Some fundamental constants */ |
|
| 95 |
-static const UTF32 UNI_REPLACEMENT_CHAR = 0x0000FFFD; |
|
| 96 |
-static const UTF32 UNI_MAX_BMP = 0x0000FFFF; |
|
| 97 |
-static const UTF32 UNI_MAX_UTF16 = 0x0010FFFF; |
|
| 98 |
-static const UTF32 UNI_MAX_UTF32 = 0x7FFFFFFF; |
|
| 99 |
-static const UTF32 UNI_MAX_LEGAL_UTF32 = 0x0010FFFF; |
|
| 100 |
- |
|
| 101 |
-enum ConversionResult |
|
| 102 |
-{
|
|
| 103 |
- conversionOK, /* conversion successful */ |
|
| 104 |
- sourceExhausted, /* partial character in source, but hit end */ |
|
| 105 |
- targetExhausted, /* insuff. room in target for conversion */ |
|
| 106 |
- sourceIllegal /* source sequence is illegal/malformed */ |
|
| 107 |
-}; |
|
| 108 |
- |
|
| 109 |
-enum ConversionFlags |
|
| 110 |
-{
|
|
| 111 |
- strictConversion, |
|
| 112 |
- lenientConversion |
|
| 113 |
-}; |
|
| 114 |
- |
|
| 115 |
-ConversionResult ConvertUTF8toUTF16(const UTF8 **, const UTF8 *, UTF16 **, UTF16 *, ConversionFlags); |
|
| 116 |
- |
|
| 117 |
-ConversionResult ConvertUTF16toUTF8(const UTF16 **, const UTF16 *, UTF8 **, UTF8 *, ConversionFlags); |
|
| 118 |
- |
|
| 119 |
-ConversionResult ConvertUTF8toUTF32(const UTF8 **, const UTF8 *, UTF32 **, UTF32 *, ConversionFlags); |
|
| 120 |
- |
|
| 121 |
-ConversionResult ConvertUTF32toUTF8(const UTF32 **, const UTF32 *, UTF8 **, UTF8 *, ConversionFlags); |
|
| 122 |
- |
|
| 123 |
-ConversionResult ConvertUTF16toUTF32(const UTF16 **, const UTF16 *, UTF32 **, UTF32 *, ConversionFlags); |
|
| 124 |
- |
|
| 125 |
-ConversionResult ConvertUTF32toUTF16(const UTF32 **, const UTF32 *, UTF16 **, UTF16 *, ConversionFlags); |
|
| 126 |
- |
|
| 127 |
-bool isLegalUTF8Sequence(const UTF8 *, const UTF8 *); |
|
| 128 |
- |
|
| 129 |
-/* --------------------------------------------------------------------- */ |
| ... | ... |
@@ -79,8 +79,7 @@ |
| 79 | 79 |
|
| 80 | 80 |
------------------------------------------------------------------------ */ |
| 81 | 81 |
|
| 82 |
-#ifndef _CONVERTUTF_H_ |
|
| 83 |
-#define _CONVERTUTF_H_ |
|
| 82 |
+#pragma once |
|
| 84 | 83 |
|
| 85 | 84 |
/* --------------------------------------------------------------------- |
| 86 | 85 |
The following 4 definitions are compiler-specific. |
| ... | ... |
@@ -130,5 +129,3 @@ ConversionResult ConvertUTF32toUTF16(const UTF32 **, const UTF32 *, UTF16 **, UT |
| 130 | 129 |
bool isLegalUTF8Sequence(const UTF8 *, const UTF8 *); |
| 131 | 130 |
|
| 132 | 131 |
/* --------------------------------------------------------------------- */ |
| 133 |
- |
|
| 134 |
-#endif |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,134 @@ |
| 1 |
+/* |
|
| 2 |
+ * Copyright 2001-2004 Unicode, Inc. |
|
| 3 |
+ * |
|
| 4 |
+ * Disclaimer |
|
| 5 |
+ * |
|
| 6 |
+ * This source code is provided as is by Unicode, Inc. No claims are |
|
| 7 |
+ * made as to fitness for any particular purpose. No warranties of any |
|
| 8 |
+ * kind are expressed or implied. The recipient agrees to determine |
|
| 9 |
+ * applicability of information provided. If this file has been |
|
| 10 |
+ * purchased on magnetic or optical media from Unicode, Inc., the |
|
| 11 |
+ * sole remedy for any claim will be exchange of defective media |
|
| 12 |
+ * within 90 days of receipt. |
|
| 13 |
+ * |
|
| 14 |
+ * Limitations on Rights to Redistribute This Code |
|
| 15 |
+ * |
|
| 16 |
+ * Unicode, Inc. hereby grants the right to freely use the information |
|
| 17 |
+ * supplied in this file in the creation of products supporting the |
|
| 18 |
+ * Unicode Standard, and to make copies of this file in any form |
|
| 19 |
+ * for internal or external distribution as long as this notice |
|
| 20 |
+ * remains attached. |
|
| 21 |
+ */ |
|
| 22 |
+ |
|
| 23 |
+/* --------------------------------------------------------------------- |
|
| 24 |
+ |
|
| 25 |
+ Conversions between UTF32, UTF-16, and UTF-8. Header file. |
|
| 26 |
+ |
|
| 27 |
+ Several funtions are included here, forming a complete set of |
|
| 28 |
+ conversions between the three formats. UTF-7 is not included |
|
| 29 |
+ here, but is handled in a separate source file. |
|
| 30 |
+ |
|
| 31 |
+ Each of these routines takes pointers to input buffers and output |
|
| 32 |
+ buffers. The input buffers are const. |
|
| 33 |
+ |
|
| 34 |
+ Each routine converts the text between *sourceStart and sourceEnd, |
|
| 35 |
+ putting the result into the buffer between *targetStart and |
|
| 36 |
+ targetEnd. Note: the end pointers are *after* the last item: e.g. |
|
| 37 |
+ *(sourceEnd - 1) is the last item. |
|
| 38 |
+ |
|
| 39 |
+ The return result indicates whether the conversion was successful, |
|
| 40 |
+ and if not, whether the problem was in the source or target buffers. |
|
| 41 |
+ (Only the first encountered problem is indicated.) |
|
| 42 |
+ |
|
| 43 |
+ After the conversion, *sourceStart and *targetStart are both |
|
| 44 |
+ updated to point to the end of last text successfully converted in |
|
| 45 |
+ the respective buffers. |
|
| 46 |
+ |
|
| 47 |
+ Input parameters: |
|
| 48 |
+ sourceStart - pointer to a pointer to the source buffer. |
|
| 49 |
+ The contents of this are modified on return so that |
|
| 50 |
+ it points at the next thing to be converted. |
|
| 51 |
+ targetStart - similarly, pointer to pointer to the target buffer. |
|
| 52 |
+ sourceEnd, targetEnd - respectively pointers to the ends of the |
|
| 53 |
+ two buffers, for overflow checking only. |
|
| 54 |
+ |
|
| 55 |
+ These conversion functions take a ConversionFlags argument. When this |
|
| 56 |
+ flag is set to strict, both irregular sequences and isolated surrogates |
|
| 57 |
+ will cause an error. When the flag is set to lenient, both irregular |
|
| 58 |
+ sequences and isolated surrogates are converted. |
|
| 59 |
+ |
|
| 60 |
+ Whether the flag is strict or lenient, all illegal sequences will cause |
|
| 61 |
+ an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>, |
|
| 62 |
+ or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code |
|
| 63 |
+ must check for illegal sequences. |
|
| 64 |
+ |
|
| 65 |
+ When the flag is set to lenient, characters over 0x10FFFF are converted |
|
| 66 |
+ to the replacement character; otherwise (when the flag is set to strict) |
|
| 67 |
+ they constitute an error. |
|
| 68 |
+ |
|
| 69 |
+ Output parameters: |
|
| 70 |
+ The value "sourceIllegal" is returned from some routines if the input |
|
| 71 |
+ sequence is malformed. When "sourceIllegal" is returned, the source |
|
| 72 |
+ value will point to the illegal value that caused the problem. E.g., |
|
| 73 |
+ in UTF-8 when a sequence is malformed, it points to the start of the |
|
| 74 |
+ malformed sequence. |
|
| 75 |
+ |
|
| 76 |
+ Author: Mark E. Davis, 1994. |
|
| 77 |
+ Rev History: Rick McGowan, fixes & updates May 2001. |
|
| 78 |
+ Fixes & updates, Sept 2001. |
|
| 79 |
+ |
|
| 80 |
+------------------------------------------------------------------------ */ |
|
| 81 |
+ |
|
| 82 |
+#ifndef _CONVERTUTF_H_ |
|
| 83 |
+#define _CONVERTUTF_H_ |
|
| 84 |
+ |
|
| 85 |
+/* --------------------------------------------------------------------- |
|
| 86 |
+ The following 4 definitions are compiler-specific. |
|
| 87 |
+ The C standard does not guarantee that wchar_t has at least |
|
| 88 |
+ 16 bits, so wchar_t is no less portable than unsigned short! |
|
| 89 |
+ All should be unsigned values to avoid sign extension during |
|
| 90 |
+ bit mask & shift operations. |
|
| 91 |
+------------------------------------------------------------------------ */ |
|
| 92 |
+ |
|
| 93 |
+typedef unsigned long UTF32; /* at least 32 bits */ |
|
| 94 |
+typedef unsigned short UTF16; /* at least 16 bits */ |
|
| 95 |
+typedef unsigned char UTF8; /* typically 8 bits */ |
|
| 96 |
+ |
|
| 97 |
+/* Some fundamental constants */ |
|
| 98 |
+static const UTF32 UNI_REPLACEMENT_CHAR = 0x0000FFFD; |
|
| 99 |
+static const UTF32 UNI_MAX_BMP = 0x0000FFFF; |
|
| 100 |
+static const UTF32 UNI_MAX_UTF16 = 0x0010FFFF; |
|
| 101 |
+static const UTF32 UNI_MAX_UTF32 = 0x7FFFFFFF; |
|
| 102 |
+static const UTF32 UNI_MAX_LEGAL_UTF32 = 0x0010FFFF; |
|
| 103 |
+ |
|
| 104 |
+enum ConversionResult |
|
| 105 |
+{
|
|
| 106 |
+ conversionOK, /* conversion successful */ |
|
| 107 |
+ sourceExhausted, /* partial character in source, but hit end */ |
|
| 108 |
+ targetExhausted, /* insuff. room in target for conversion */ |
|
| 109 |
+ sourceIllegal /* source sequence is illegal/malformed */ |
|
| 110 |
+}; |
|
| 111 |
+ |
|
| 112 |
+enum ConversionFlags |
|
| 113 |
+{
|
|
| 114 |
+ strictConversion, |
|
| 115 |
+ lenientConversion |
|
| 116 |
+}; |
|
| 117 |
+ |
|
| 118 |
+ConversionResult ConvertUTF8toUTF16(const UTF8 **, const UTF8 *, UTF16 **, UTF16 *, ConversionFlags); |
|
| 119 |
+ |
|
| 120 |
+ConversionResult ConvertUTF16toUTF8(const UTF16 **, const UTF16 *, UTF8 **, UTF8 *, ConversionFlags); |
|
| 121 |
+ |
|
| 122 |
+ConversionResult ConvertUTF8toUTF32(const UTF8 **, const UTF8 *, UTF32 **, UTF32 *, ConversionFlags); |
|
| 123 |
+ |
|
| 124 |
+ConversionResult ConvertUTF32toUTF8(const UTF32 **, const UTF32 *, UTF8 **, UTF8 *, ConversionFlags); |
|
| 125 |
+ |
|
| 126 |
+ConversionResult ConvertUTF16toUTF32(const UTF16 **, const UTF16 *, UTF32 **, UTF32 *, ConversionFlags); |
|
| 127 |
+ |
|
| 128 |
+ConversionResult ConvertUTF32toUTF16(const UTF32 **, const UTF32 *, UTF16 **, UTF16 *, ConversionFlags); |
|
| 129 |
+ |
|
| 130 |
+bool isLegalUTF8Sequence(const UTF8 *, const UTF8 *); |
|
| 131 |
+ |
|
| 132 |
+/* --------------------------------------------------------------------- */ |
|
| 133 |
+ |
|
| 134 |
+#endif |