]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3string.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3string.h
diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3string.h b/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3string.h
new file mode 100644 (file)
index 0000000..15b3b25
--- /dev/null
@@ -0,0 +1,273 @@
+/** \file\r
+ * Simple string interface allows indiscriminate allocation of strings\r
+ * such that they can be allocated all over the place and released in \r
+ * one chunk via a string factory - saves lots of hassle in remembering what\r
+ * strings were allocated where.\r
+ */\r
+#ifndef        _ANTLR3_STRING_H\r
+#define        _ANTLR3_STRING_H\r
+\r
+// [The "BSD licence"]\r
+// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
+// http://www.temporal-wave.com\r
+// http://www.linkedin.com/in/jimidle\r
+//\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions\r
+// are met:\r
+// 1. Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+// 2. Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the distribution.\r
+// 3. The name of the author may not be used to endorse or promote products\r
+//    derived from this software without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#include    <antlr3defs.h>\r
+#include    <antlr3collections.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/** Base string class tracks the allocations and provides simple string\r
+ *  tracking functions. Mostly you can work directly on the string for things\r
+ *  that don't reallocate it, like strchr() etc. Perhaps someone will want to provide implementations for UTF8\r
+ *  and so on.\r
+ */\r
+typedef        struct ANTLR3_STRING_struct\r
+{\r
+\r
+    /** The factory that created this string\r
+     */\r
+    pANTLR3_STRING_FACTORY     factory;\r
+\r
+    /** Pointer to the current string value (starts at NULL unless\r
+     *  the string allocator is told to create it with a pre known size.\r
+     */\r
+    pANTLR3_UINT8              chars;\r
+\r
+    /** Current length of the string up to and not including, the trailing '\0'\r
+     *  Note that the actual allocation (->size)\r
+     *  is always at least one byte more than this to accommodate trailing '\0'\r
+     */\r
+    ANTLR3_UINT32              len;\r
+\r
+    /** Current size of the string in bytes including the trailing '\0'\r
+     */\r
+    ANTLR3_UINT32              size;\r
+\r
+    /** Index of string (allocation number) in case someone wants\r
+     *  to explicitly release it.\r
+     */\r
+    ANTLR3_UINT32              index;\r
+\r
+    /** Occasionally it is useful to know what the encoding of the string\r
+     *  actually is, hence it is stored here as one the ANTLR3_ENCODING_ values\r
+     */\r
+    ANTLR3_UINT8               encoding;\r
+\r
+    /** Pointer to function that sets the string value to a specific string in the default encoding\r
+     *  for this string. For instance, if this is ASCII 8 bit, then this function is the same as set8\r
+     *  but if the encoding is 16 bit, then the pointer is assumed to point to 16 bit characters not\r
+     *  8 bit.\r
+     */\r
+    pANTLR3_UINT8   (*set)     (struct ANTLR3_STRING_struct * string, const char * chars);\r
+   \r
+    /** Pointer to function that sets the string value to a specific 8 bit string in the default encoding\r
+     *  for this string. For instance, if this is a 16 bit string, then this function is the same as set8\r
+     *  but if the encoding is 16 bit, then the pointer is assumed to point to 8 bit characters that must\r
+     *  be converted to 16 bit characters on the fly.\r
+     */\r
+    pANTLR3_UINT8   (*set8)    (struct ANTLR3_STRING_struct * string, const char * chars);\r
+\r
+    /** Pointer to function adds a raw char * type pointer in the default encoding\r
+     *  for this string. For instance, if this is ASCII 8 bit, then this function is the same as append8\r
+     *  but if the encoding is 16 bit, then the pointer is assumed to point to 16 bit characters not\r
+     *  8 bit.\r
+     */\r
+    pANTLR3_UINT8   (*append)  (struct ANTLR3_STRING_struct * string, const char * newbit);\r
+\r
+    /** Pointer to function adds a raw char * type pointer in the default encoding\r
+     *  for this string. For instance, if this is a 16 bit string, then this function assumes the pointer\r
+     *  points to 8 bit characters that must be converted on the fly.\r
+     */\r
+    pANTLR3_UINT8   (*append8) (struct ANTLR3_STRING_struct * string, const char * newbit);\r
+\r
+    /** Pointer to function that inserts the supplied string at the specified\r
+     *  offset in the current string in the default encoding for this string. For instance, if this is an 8\r
+     *  bit string, then this is the same as insert8, but if this is a 16 bit string, then the poitner\r
+     *  must point to 16 bit characters.\r
+     *  \r
+     */\r
+    pANTLR3_UINT8   (*insert)  (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, const char * newbit);\r
+\r
+    /** Pointer to function that inserts the supplied string at the specified\r
+     *  offset in the current string in the default encoding for this string. For instance, if this is a 16 bit string\r
+     *  then the pointer is assumed to point at 8 bit characteres that must be converted on the fly.\r
+     */\r
+    pANTLR3_UINT8   (*insert8) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, const char * newbit);\r
+\r
+    /** Pointer to function that sets the string value to a copy of the supplied string (strings must be in the \r
+     *  same encoding.\r
+     */\r
+    pANTLR3_UINT8   (*setS)    (struct ANTLR3_STRING_struct * string, struct ANTLR3_STRING_struct * chars);\r
+\r
+    /** Pointer to function appends a copy of the characters contained in another string. Strings must be in the\r
+     *  same encoding.\r
+     */\r
+    pANTLR3_UINT8   (*appendS) (struct ANTLR3_STRING_struct * string, struct ANTLR3_STRING_struct * newbit);\r
+\r
+    /** Pointer to function that inserts a copy of the characters in the supplied string at the specified\r
+     *  offset in the current string. strings must be in the same encoding.\r
+     */\r
+    pANTLR3_UINT8   (*insertS) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, struct ANTLR3_STRING_struct * newbit);\r
+\r
+    /** Pointer to function that inserts the supplied integer in string form at the specified\r
+     *  offset in the current string.\r
+     */\r
+    pANTLR3_UINT8   (*inserti) (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 point, ANTLR3_INT32 i);\r
+\r
+    /** Pointer to function that adds a single character to the end of the string, in the encoding of the\r
+     *  string - 8 bit, 16 bit, utf-8 etc. Input is a single UTF32 (32 bits wide integer) character.\r
+     */\r
+    pANTLR3_UINT8   (*addc)    (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 c);\r
+\r
+    /** Pointer to function that adds the stringified representation of an integer\r
+     *  to the string.\r
+     */\r
+    pANTLR3_UINT8   (*addi)    (struct ANTLR3_STRING_struct * string, ANTLR3_INT32 i);\r
+\r
+    /** Pointer to function that compares the text of a string to the supplied\r
+     *  8 bit character string and returns a result a la strcmp()\r
+     */\r
+    ANTLR3_UINT32   (*compare8)        (struct ANTLR3_STRING_struct * string, const char * compStr);\r
+\r
+    /** Pointer to a function that compares the text of a string with the supplied character string\r
+     *  (which is assumed to be in the same encoding as the string itself) and returns a result\r
+     *  a la strcmp()\r
+     */\r
+    ANTLR3_UINT32   (*compare) (struct ANTLR3_STRING_struct * string, const char * compStr);\r
+\r
+    /** Pointer to a function that compares the text of a string with the supplied string\r
+     *  (which is assumed to be in the same encoding as the string itself) and returns a result\r
+     *  a la strcmp()\r
+     */\r
+    ANTLR3_UINT32   (*compareS)        (struct ANTLR3_STRING_struct * string, struct ANTLR3_STRING_struct * compStr);\r
+\r
+    /** Pointer to a function that returns the character indexed at the supplied\r
+     *  offset as a 32 bit character.\r
+     */\r
+    ANTLR3_UCHAR    (*charAt)  (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 offset);\r
+\r
+    /** Pointer to a function that returns a substring of the supplied string a la .subString(s,e)\r
+     *  in the Java language.\r
+     */\r
+    struct ANTLR3_STRING_struct *\r
+                                       (*subString)    (struct ANTLR3_STRING_struct * string, ANTLR3_UINT32 startIndex, ANTLR3_UINT32 endIndex);\r
+\r
+    /** Pointer to a function that returns the integer representation of any numeric characters\r
+     *  at the beginning of the string\r
+     */\r
+    ANTLR3_INT32       (*toInt32)          (struct ANTLR3_STRING_struct * string);\r
+\r
+    /** Pointer to a function that yields an 8 bit string regardless of the encoding of the supplied\r
+     *  string. This is useful when you want to use the text of a token in some way that requires an 8 bit\r
+     *  value, such as the key for a hashtable. The function is required to produce a usable string even\r
+     *  if the text given as input has characters that do not fit in 8 bit space, it will replace them\r
+     *  with some arbitrary character such as '?'\r
+     */\r
+    struct ANTLR3_STRING_struct *\r
+                                       (*to8)      (struct ANTLR3_STRING_struct * string);\r
+\r
+       /// Pointer to a function that yields a UT8 encoded string of the current string,\r
+       /// regardless of the current encoding of the string. Because there is currently no UTF8\r
+       /// handling in the string class, it creates therefore, a string that is useful only for read only \r
+       /// applications as it will not contain methods that deal with UTF8 at the moment.\r
+       ///\r
+       struct ANTLR3_STRING_struct *\r
+                                       (*toUTF8)       (struct ANTLR3_STRING_struct * string);\r
+       \r
+}\r
+    ANTLR3_STRING;\r
+\r
+/** Definition of the string factory interface, which creates and tracks\r
+ *  strings for you of various shapes and sizes.\r
+ */\r
+typedef struct ANTLR3_STRING_FACTORY_struct\r
+{\r
+    /** List of all the strings that have been allocated by the factory\r
+     */\r
+    pANTLR3_VECTOR    strings;\r
+\r
+    /* Index of next string that we allocate\r
+     */\r
+    ANTLR3_UINT32   index;\r
+\r
+    /** Pointer to function that manufactures an empty string\r
+     */\r
+    pANTLR3_STRING  (*newRaw)  (struct ANTLR3_STRING_FACTORY_struct * factory);\r
+\r
+    /** Pointer to function that manufactures a raw string with no text in it but space for size\r
+     *  characters.\r
+     */\r
+    pANTLR3_STRING  (*newSize) (struct ANTLR3_STRING_FACTORY_struct * factory, ANTLR3_UINT32 size);\r
+\r
+    /** Pointer to function that manufactures a string from a given pointer and length. The pointer is assumed\r
+     *  to point to characters in the same encoding as the string type, hence if this is a 16 bit string the\r
+     *  pointer should point to 16 bit characters.\r
+     */\r
+    pANTLR3_STRING  (*newPtr)  (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string, ANTLR3_UINT32 size);\r
+\r
+    /** Pointer to function that manufactures a string from a given pointer and length. The pointer is assumed to\r
+     *  point at 8 bit characters which must be converted on the fly to the encoding of the actual string.\r
+     */\r
+    pANTLR3_STRING  (*newPtr8) (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string, ANTLR3_UINT32 size);\r
+\r
+    /** Pointer to function that manufactures a string from a given pointer and works out the length. The pointer is \r
+     *  assumed to point to characters in the same encoding as the string itself, i.e. 16 bit if a 16 bit\r
+     *  string and so on.\r
+     */\r
+    pANTLR3_STRING  (*newStr)  (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string);\r
+\r
+    /** Pointer to function that manufactures a string from a given pointer and length. The pointer should\r
+     *  point to 8 bit characters regardless of the actual encoding of the string. The 8 bit characters\r
+     *  will be converted to the actual string encoding on the fly.\r
+     */\r
+    pANTLR3_STRING  (*newStr8) (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_UINT8 string);\r
+\r
+    /** Pointer to function that deletes the string altogether\r
+     */\r
+    void           (*destroy)  (struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_STRING string);\r
+\r
+    /** Pointer to function that returns a copy of the string in printable form without any control\r
+     *  characters in it.\r
+     */\r
+    pANTLR3_STRING  (*printable)(struct ANTLR3_STRING_FACTORY_struct * factory, pANTLR3_STRING string);\r
+\r
+    /** Pointer to function that closes the factory\r
+     */\r
+    void           (*close)    (struct ANTLR3_STRING_FACTORY_struct * factory);\r
+\r
+}\r
+    ANTLR3_STRING_FACTORY;\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r