]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3convertutf.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3convertutf.h
diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3convertutf.h b/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3convertutf.h
new file mode 100644 (file)
index 0000000..1339373
--- /dev/null
@@ -0,0 +1,166 @@
+/*\r
+ * Copyright 2001-2004 Unicode, Inc.\r
+ * \r
+ * Disclaimer\r
+ * \r
+ * This source code is provided as is by Unicode, Inc. No claims are\r
+ * made as to fitness for any particular purpose. No warranties of any\r
+ * kind are expressed or implied. The recipient agrees to determine\r
+ * applicability of information provided. If this file has been\r
+ * purchased on magnetic or optical media from Unicode, Inc., the\r
+ * sole remedy for any claim will be exchange of defective media\r
+ * within 90 days of receipt.\r
+ * \r
+ * Limitations on Rights to Redistribute This Code\r
+ * \r
+ * Unicode, Inc. hereby grants the right to freely use the information\r
+ * supplied in this file in the creation of products supporting the\r
+ * Unicode Standard, and to make copies of this file in any form\r
+ * for internal or external distribution as long as this notice\r
+ * remains attached.\r
+ */\r
+\r
+/* ---------------------------------------------------------------------\r
+\r
+    Conversions between UTF32, UTF-16, and UTF-8.  Header file.\r
+\r
+    Several functions are included here, forming a complete set of\r
+    conversions between the three formats.  UTF-7 is not included\r
+    here, but is handled in a separate source file.\r
+\r
+    Each of these routines takes pointers to input buffers and output\r
+    buffers.  The input buffers are const.\r
+\r
+    Each routine converts the text between *sourceStart and sourceEnd,\r
+    putting the result into the buffer between *targetStart and\r
+    targetEnd. Note: the end pointers are *after* the last item: e.g. \r
+    *(sourceEnd - 1) is the last item.\r
+\r
+    The return result indicates whether the conversion was successful,\r
+    and if not, whether the problem was in the source or target buffers.\r
+    (Only the first encountered problem is indicated.)\r
+\r
+    After the conversion, *sourceStart and *targetStart are both\r
+    updated to point to the end of last text successfully converted in\r
+    the respective buffers.\r
+\r
+    Input parameters:\r
+       sourceStart - pointer to a pointer to the source buffer.\r
+               The contents of this are modified on return so that\r
+               it points at the next thing to be converted.\r
+       targetStart - similarly, pointer to pointer to the target buffer.\r
+       sourceEnd, targetEnd - respectively pointers to the ends of the\r
+               two buffers, for overflow checking only.\r
+\r
+    These conversion functions take a ConversionFlags argument. When this\r
+    flag is set to strict, both irregular sequences and isolated surrogates\r
+    will cause an error.  When the flag is set to lenient, both irregular\r
+    sequences and isolated surrogates are converted.\r
+\r
+    Whether the flag is strict or lenient, all illegal sequences will cause\r
+    an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,\r
+    or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code\r
+    must check for illegal sequences.\r
+\r
+    When the flag is set to lenient, characters over 0x10FFFF are converted\r
+    to the replacement character; otherwise (when the flag is set to strict)\r
+    they constitute an error.\r
+\r
+    Output parameters:\r
+       The value "sourceIllegal" is returned from some routines if the input\r
+       sequence is malformed.  When "sourceIllegal" is returned, the source\r
+       value will point to the illegal value that caused the problem. E.g.,\r
+       in UTF-8 when a sequence is malformed, it points to the start of the\r
+       malformed sequence.  \r
+\r
+    Author: Mark E. Davis, 1994.\r
+    Rev History: Rick McGowan, fixes & updates May 2001.\r
+                Fixes & updates, Sept 2001.\r
+\r
+------------------------------------------------------------------------ */\r
+\r
+/* ---------------------------------------------------------------------\r
+    The following 4 definitions are compiler-specific.\r
+    The C standard does not guarantee that wchar_t has at least\r
+    16 bits, so wchar_t is no less portable than unsigned short!\r
+    All should be unsigned values to avoid sign extension during\r
+    bit mask & shift operations.\r
+------------------------------------------------------------------------ */\r
+\r
+\r
+// Changes for ANTLR3 - Jim Idle, January 2008.\r
+// builtin types defined for Unicode types changed to\r
+// aliases for the types that are system determined by\r
+// ANTLR at compile time.\r
+//\r
+// typedef unsigned long       UTF32;  /* at least 32 bits */\r
+// typedef unsigned short      UTF16;  /* at least 16 bits */\r
+// typedef unsigned char       UTF8;   /* typically 8 bits */\r
+// typedef unsigned char       Boolean; /* 0 or 1 */\r
+\r
+#ifndef        _ANTLR3_CONVERTUTF_H\r
+#define        _ANTLR3_CONVERTUTF_H\r
+\r
+#include       <antlr3defs.h>\r
+\r
+typedef ANTLR3_UINT32  UTF32;  /* at least 32 bits */\r
+typedef ANTLR3_UINT16  UTF16;  /* at least 16 bits */\r
+typedef ANTLR3_UINT8   UTF8;   /* typically 8 bits */\r
+\r
+/* Some fundamental constants */\r
+#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD\r
+#define UNI_MAX_BMP (UTF32)0x0000FFFF\r
+#define UNI_MAX_UTF16 (UTF32)0x0010FFFF\r
+#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF\r
+#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF\r
+\r
+typedef enum {\r
+       conversionOK,           /* conversion successful */\r
+       sourceExhausted,        /* partial character in source, but hit end */\r
+       targetExhausted,        /* insuff. room in target for conversion */\r
+       sourceIllegal           /* source sequence is illegal/malformed */\r
+} ConversionResult;\r
+\r
+typedef enum {\r
+       strictConversion = 0,\r
+       lenientConversion\r
+} ConversionFlags;\r
+\r
+/* This is for C++ and does no harm in C */\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+ConversionResult ConvertUTF8toUTF16 (\r
+               const UTF8** sourceStart, const UTF8* sourceEnd, \r
+               UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);\r
+\r
+ConversionResult ConvertUTF16toUTF8 (\r
+               const UTF16** sourceStart, const UTF16* sourceEnd, \r
+               UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);\r
+               \r
+ConversionResult ConvertUTF8toUTF32 (\r
+               const UTF8** sourceStart, const UTF8* sourceEnd, \r
+               UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);\r
+\r
+ConversionResult ConvertUTF32toUTF8 (\r
+               const UTF32** sourceStart, const UTF32* sourceEnd, \r
+               UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);\r
+               \r
+ConversionResult ConvertUTF16toUTF32 (\r
+               const UTF16** sourceStart, const UTF16* sourceEnd, \r
+               UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);\r
+\r
+ConversionResult ConvertUTF32toUTF16 (\r
+               const UTF32** sourceStart, const UTF32* sourceEnd, \r
+               UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);\r
+\r
+ANTLR3_BOOLEAN isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r
+/* --------------------------------------------------------------------- */\r