• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_string.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 1998,1999 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017  * 02111-1307, USA.
00018  */
00019 
00020 
00021 #ifndef UT_STRING_H
00022 #define UT_STRING_H
00023 
00024 #include <map>
00025 #include <string>
00026 #include <string.h>
00027 
00028 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00029  * so even if it's commented out in-file that's still a lot of work for
00030  * the preprocessor to do...
00031  */
00032 #ifndef UT_TYPES_H
00033 #include "ut_types.h"
00034 #endif
00035 
00036 class UT_GrowBuf;
00037 
00038 G_BEGIN_DECLS
00039 
00040 // this function allocates (and returns a pointer to) new memory for the new string
00041 ABI_EXPORT bool  UT_XML_cloneNoAmpersands(gchar *& rszDest, const gchar * szSource);
00042 // replaces &X -> _X; allocates buffer
00043 ABI_EXPORT bool  UT_XML_cloneConvAmpersands(gchar *& rszDest, const gchar * szSource);
00044 // This function uses a static buffer to do the translation
00045 ABI_EXPORT const gchar *  UT_XML_transNoAmpersands(const gchar * szSource);
00046 
00047 ABI_EXPORT void  UT_decodeUTF8string(const gchar * p, UT_uint32 len, UT_GrowBuf * pResult);
00048 
00049 ABI_EXPORT bool  UT_isValidXML(const char *s);
00050 ABI_EXPORT bool  UT_validXML(char * s);
00051 
00052 /* ABI_EXPORT gchar *  UT_decodeXMLstring(gchar *pcIn);
00053  * This has moved to ut_xml.cpp as UT_XML::decode ()
00054  */
00055 
00056 ABI_EXPORT bool  UT_isSmartQuotableCharacter(UT_UCSChar c);
00057 ABI_EXPORT bool  UT_isSmartQuotedCharacter(UT_UCSChar c);
00058 
00060 //
00061 //  UCS-2 string (UT_UCS2Char)
00062 //
00063 //  String is built of 16-bit units (words)
00064 //
00065 //  TODO: Is this really UCS-2 or UTF-16?
00066 //  TODO:  meaning, does it support surrogates or is it intended to
00067 //  TODO:  support them at any time in the future?
00068 //  TODO: Correctly, UCS-2 does not support surrogates and UTF-16 does.
00069 //  TODO: BUT Microsoft calls their native Unicode encoding UCS-2
00070 //  TODO:  while it supports surrogates and is thus really UTF-16.
00071 //  TODO: Surrogates are Unicode characters with codepoints above
00072 //  TODO:  65535 which cannot therefore fit into a 2-byte word.
00073 //  TODO: This means that TRUE UCS-2 is a single-word encoding and
00074 //  TODO:  UTF-16 is a multi-word encoding.
00075 //
00076 //  NOTE: We shouldn't actually need 16-bit strings anymore since
00077 //  NOTE:  AbiWord is now fully converted to using 32-bit Unicode
00078 //  NOTE:  internally. The only possible needs for this is for
00079 //  NOTE:  Windows GUI, filesystem and API functions where applicable;
00080 //  NOTE:  and perhaps some file formats or external libraries
00081 //
00083 
00084 #ifdef ENABLE_UCS2_STRINGS
00085 
00086 #define UT_UCS2_isdigit(x)  (((x) >= '0') && ((x) <= '9'))  // TODO: make UNICODE-wise
00087 
00088 /*these are unicode-safe*/
00089 ABI_EXPORT bool  UT_UCS2_isupper(UT_UCS2Char c);
00090 ABI_EXPORT bool  UT_UCS2_islower(UT_UCS2Char c);
00091 ABI_EXPORT bool  UT_UCS2_isalpha(UT_UCS2Char c);
00092 ABI_EXPORT bool  UT_UCS2_isSentenceSeparator(UT_UCS2Char c);
00093 #define UT_UCS2_isalnum(x)  (UT_UCS2_isalpha(x) || UT_UCS2_isdigit(x)) // HACK: not UNICODE-safe
00094 ABI_EXPORT bool UT_UCS2_isspace(UT_UCS2Char c);
00095 #define UT_UCS2_ispunct(x)   ((!UT_UCS2_isspace(x)  &&  !UT_UCS2_isalnum(x)  &&  (x)>' '))  // HACK: not UNICODE safe
00096 
00097 // the naming convention has deviated from the above.  it's kind
00098 // of a mutant libc/C++ naming convention.
00099 ABI_EXPORT UT_UCS2Char *     UT_UCS2_strstr(const UT_UCS2Char * phaystack, const UT_UCS2Char * pneedle);
00100 ABI_EXPORT UT_sint32         UT_UCS2_strcmp(const UT_UCS2Char* left, const UT_UCS2Char* right);
00101 ABI_EXPORT UT_UCS2Char *     UT_UCS2_stristr(const UT_UCS2Char * phaystack, const UT_UCS2Char * pneedle);
00102 ABI_EXPORT UT_UCS2Char *     UT_UCS2_strcpy(UT_UCS2Char * dest, const UT_UCS2Char * src);
00103 ABI_EXPORT UT_UCS2Char *     UT_UCS2_strcpy_char(UT_UCS2Char * dest, const char * src);
00104 ABI_EXPORT char *            UT_UCS2_strcpy_to_char(char * dest, const UT_UCS2Char * src);
00105 ABI_EXPORT bool          UT_UCS2_cloneString(UT_UCS2Char ** dest, const UT_UCS2Char * src);
00106 ABI_EXPORT bool          UT_UCS2_cloneString_char(UT_UCS2Char ** dest, const char * src);
00107 ABI_EXPORT UT_UCS2Char *     UT_UCS2_strncpy(UT_UCS2Char * dest, const UT_UCS2Char * src, UT_uint32 n);
00108 ABI_EXPORT UT_UCS2Char *     UT_UCS2_strnrev(UT_UCS2Char * dest, UT_uint32 n);
00109 
00110 ABI_EXPORT UT_UCS2Char       UT_UCS2_tolower(UT_UCS2Char c);
00111 ABI_EXPORT UT_UCS2Char       UT_UCS2_toupper(UT_UCS2Char c);
00112 
00113 #endif
00114 
00115 // Don't ifdef this one out since MSWord importer uses it
00116 
00117 ABI_EXPORT UT_uint32         UT_UCS2_strlen(const UT_UCS2Char * string);
00118 
00120 //
00121 //  UCS-4 string (UT_UCS4Char)
00122 //
00123 //  String is built of 32-bit units (longs)
00124 //
00125 //  NOTE: Ambiguity between UCS-2 and UTF-16 above makes no difference
00126 //  NOTE:  in the case of UCS-4 and UTF-32 since they really are
00127 //  NOTE:  identical
00128 //
00130 
00131 /*these are unicode-safe*/
00132 ABI_EXPORT bool  UT_UCS4_isupper(UT_UCS4Char c);
00133 ABI_EXPORT bool  UT_UCS4_islower(UT_UCS4Char c);
00134 ABI_EXPORT bool  UT_UCS4_isalpha(UT_UCS4Char c);
00135 ABI_EXPORT bool  UT_UCS4_isSentenceSeparator(UT_UCS4Char c);
00136 ABI_EXPORT bool  UT_UCS4_isdigit(UT_UCS4Char c);
00137 #define UT_UCS4_isalnum(x)  (UT_UCS4_isalpha(x) || UT_UCS4_isdigit(x)) // HACK: not UNICODE-safe
00138 ABI_EXPORT bool UT_UCS4_isspace(UT_UCS4Char c);
00139 #define UT_UCS4_ispunct(x)   ((!UT_UCS4_isspace(x)  &&  !UT_UCS4_isalnum(x)  &&  (x)>' '))  // HACK: not UNICODE safe
00140 
00141 // the naming convention has deviated from the above.  it's kind
00142 // of a mutant libc/C++ naming convention.
00143 ABI_EXPORT UT_sint32         UT_UCS4_strcmp(const UT_UCS4Char* left, const UT_UCS4Char* right);
00144 ABI_EXPORT UT_UCS4Char *     UT_UCS4_strstr(const UT_UCS4Char * phaystack, const UT_UCS4Char * pneedle);
00145 ABI_EXPORT UT_UCS4Char *     UT_UCS4_stristr(const UT_UCS4Char * phaystack, const UT_UCS4Char * pneedle);
00146 ABI_EXPORT UT_uint32         UT_UCS4_strlen(const UT_UCS4Char * string);
00147 ABI_EXPORT UT_uint32         UT_UCS4_strlen_as_char(const UT_UCS4Char * string);
00148 ABI_EXPORT UT_UCS4Char *     UT_UCS4_strcpy(UT_UCS4Char * dest, const UT_UCS4Char * src);
00149 ABI_EXPORT UT_UCS4Char *     UT_UCS4_strcpy_char(UT_UCS4Char * dest, const char * src);
00150 ABI_EXPORT UT_UCS4Char *     UT_UCS4_strncpy_char(UT_UCS4Char * dest, const char * src, int);
00151 ABI_EXPORT UT_UCS4Char *     UT_UCS4_strcpy_utf8_char(UT_UCS4Char * dest, const char * src);
00152 ABI_EXPORT char *            UT_UCS4_strcpy_to_char(char * dest, const UT_UCS4Char * src);
00153 ABI_EXPORT char *            UT_UCS4_strncpy_to_char(char * dest, const UT_UCS4Char * src, int);
00154 ABI_EXPORT bool              UT_UCS4_cloneString(UT_UCS4Char ** dest, const UT_UCS4Char * src);
00155 ABI_EXPORT bool              UT_UCS4_cloneString_char(UT_UCS4Char ** dest, const char * src);
00156 ABI_EXPORT UT_UCS4Char *     UT_UCS4_strncpy(UT_UCS4Char * dest, const UT_UCS4Char * src, UT_uint32 n);
00157 ABI_EXPORT UT_UCS4Char *     UT_UCS4_strnrev(UT_UCS4Char * dest, UT_uint32 n);
00158 
00159 ABI_EXPORT UT_UCS4Char       UT_UCS4_tolower(UT_UCS4Char c);
00160 ABI_EXPORT UT_UCS4Char       UT_UCS4_toupper(UT_UCS4Char c);
00161 
00162 
00163 ABI_EXPORT void UT_parse_attributes(const char * attributes,
00164                                     std::map<std::string, std::string> & map);
00165 ABI_EXPORT void UT_parse_properties(const char * props,
00166                                     std::map<std::string, std::string> & map);
00167 
00168 // implemented in UT_strptime.cpp - see strptime() as it is not avail on win.
00169 extern "C" {
00170 ABI_EXPORT char *UT_strptime (const char *buf, const char *format, struct tm *tm);
00171 }
00172 
00173 
00174 #ifdef WIN32
00175 #define snprintf _snprintf
00176 
00177 #define _(String) (String)
00178 #define N_(String) (String)
00179 
00180 #endif /* WIN32 */
00181 
00182 #if defined (SNPRINTF_MISSING)
00183   extern int snprintf(char *str, size_t size, const  char  *format, ...);
00184 #endif
00185 
00186 /*
00187  this one prints floating point value but using dot as fractional serparator
00188  independent of the current locale's settings.
00189 */
00190 ABI_EXPORT const char*  std_size_string(float f);
00191 
00192 
00193 #include <fribidi.h>
00194 
00195 typedef FriBidiCharType UT_BidiCharType;
00196 
00197 #define UT_BIDI_LTR FRIBIDI_TYPE_LTR
00198 #define UT_BIDI_RTL FRIBIDI_TYPE_RTL
00199 #define UT_BIDI_WS FRIBIDI_TYPE_WS
00200 #define UT_BIDI_EN FRIBIDI_TYPE_EN
00201 #define UT_BIDI_ES FRIBIDI_TYPE_ES
00202 #define UT_BIDI_ET FRIBIDI_TYPE_ET
00203 #define UT_BIDI_AN FRIBIDI_TYPE_AN
00204 #define UT_BIDI_CS FRIBIDI_TYPE_CS
00205 #define UT_BIDI_BS FRIBIDI_TYPE_BS
00206 #define UT_BIDI_SS FRIBIDI_TYPE_SS
00207 #define UT_BIDI_AL FRIBIDI_TYPE_AL
00208 #define UT_BIDI_NSM FRIBIDI_TYPE_NSM
00209 #define UT_BIDI_RLE FRIBIDI_TYPE_RLE
00210 #define UT_BIDI_LRE FRIBIDI_TYPE_LRE
00211 #define UT_BIDI_LRO FRIBIDI_TYPE_LRO
00212 #define UT_BIDI_RLO FRIBIDI_TYPE_RLO
00213 #define UT_BIDI_PDF FRIBIDI_TYPE_PDF
00214 #define UT_BIDI_ON FRIBIDI_TYPE_ON
00215 
00216 
00217 #define UT_BIDI_UNSET FRIBIDI_TYPE_UNSET
00218 #define UT_BIDI_IGNORE FRIBIDI_TYPE_IGNORE
00219 
00220 #define UT_BIDI_IS_STRONG FRIBIDI_IS_STRONG
00221 #define UT_BIDI_IS_WEAK FRIBIDI_IS_WEAK
00222 #define UT_BIDI_IS_NUMBER FRIBIDI_IS_NUMBER
00223 #define UT_BIDI_IS_RTL FRIBIDI_IS_RTL
00224 #define UT_BIDI_IS_NEUTRAL FRIBIDI_IS_NEUTRAL
00225 #define UT_BIDI_IS_LETTER FRIBIDI_IS_LETTER
00226 #define UT_BIDI_IS_NSM(x) ((x) & FRIBIDI_MASK_NSM)
00227 
00228 
00229 ABI_EXPORT UT_BidiCharType UT_bidiGetCharType(UT_UCS4Char c);
00230 
00231 ABI_EXPORT bool            UT_bidiMapLog2Vis(const UT_UCS4Char * pStrIn, UT_uint32 len, UT_BidiCharType baseDir,
00232                                              UT_uint32 *pL2V, UT_uint32 * pV2L, UT_Byte * pEmbed);
00233 
00234 ABI_EXPORT bool            UT_bidiReorderString(const UT_UCS4Char * pStrIn, UT_uint32 len, UT_BidiCharType baseDir,
00235                                                 UT_UCS4Char * pStrOut);
00236 
00237 
00238 ABI_EXPORT bool            UT_bidiGetMirrorChar(UT_UCS4Char c, UT_UCS4Char &mc);
00239 
00240 G_END_DECLS
00241 
00242 #endif /* UT_STRING_H */

Generated on Mon May 28 2012 for AbiWord by  doxygen 1.7.1