00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #ifndef _CPL_STRING_H_INCLUDED
00032 #define _CPL_STRING_H_INCLUDED
00033 
00034 #include "cpl_vsi.h"
00035 #include "cpl_error.h"
00036 #include "cpl_conv.h"
00037 
00056 CPL_C_START
00057 
00058 char CPL_DLL **CSLAddString(char **papszStrList, const char *pszNewString);
00059 int CPL_DLL CSLCount(char **papszStrList);
00060 const char CPL_DLL *CSLGetField( char **, int );
00061 void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList);
00062 char CPL_DLL **CSLDuplicate(char **papszStrList);
00063 char CPL_DLL **CSLMerge( char **papszOrig, char **papszOverride );
00064 
00065 char CPL_DLL **CSLTokenizeString(const char *pszString );
00066 char CPL_DLL **CSLTokenizeStringComplex(const char *pszString,
00067                                    const char *pszDelimiter,
00068                                    int bHonourStrings, int bAllowEmptyTokens );
00069 char CPL_DLL **CSLTokenizeString2( const char *pszString, 
00070                                    const char *pszDelimeter, 
00071                                    int nCSLTFlags );
00072 
00073 #define CSLT_HONOURSTRINGS      0x0001
00074 #define CSLT_ALLOWEMPTYTOKENS   0x0002
00075 #define CSLT_PRESERVEQUOTES     0x0004
00076 #define CSLT_PRESERVEESCAPES    0x0008
00077 #define CSLT_STRIPLEADSPACES    0x0010
00078 #define CSLT_STRIPENDSPACES     0x0020
00079 
00080 int CPL_DLL CSLPrint(char **papszStrList, FILE *fpOut);
00081 char CPL_DLL **CSLLoad(const char *pszFname);
00082 int CPL_DLL CSLSave(char **papszStrList, const char *pszFname);
00083 
00084 char CPL_DLL **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, 
00085                          char **papszNewLines);
00086 char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo, 
00087                                const char *pszNewLine);
00088 char CPL_DLL **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
00089                          int nNumToRemove, char ***ppapszRetStrings);
00090 int CPL_DLL CSLFindString( char **, const char * );
00091 int CPL_DLL CSLPartialFindString( char **papszHaystack, 
00092         const char * pszNeedle );
00093 int CPL_DLL CSLFindName(char **papszStrList, const char *pszName);
00094 int CPL_DLL CSLTestBoolean( const char *pszValue );
00095 int CPL_DLL CSLFetchBoolean( char **papszStrList, const char *pszKey, 
00096                              int bDefault );
00097 
00098 const char CPL_DLL *CPLSPrintf(const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
00099 char CPL_DLL **CSLAppendPrintf(char **papszStrList, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3);
00100 int CPL_DLL CPLVASPrintf(char **buf, const char *fmt, va_list args );
00101 
00102 const char CPL_DLL *
00103       CPLParseNameValue(const char *pszNameValue, char **ppszKey );
00104 const char CPL_DLL *
00105       CSLFetchNameValue(char **papszStrList, const char *pszName);
00106 char CPL_DLL **
00107       CSLFetchNameValueMultiple(char **papszStrList, const char *pszName);
00108 char CPL_DLL **
00109       CSLAddNameValue(char **papszStrList, 
00110                       const char *pszName, const char *pszValue);
00111 char CPL_DLL **
00112       CSLSetNameValue(char **papszStrList, 
00113                       const char *pszName, const char *pszValue);
00114 void CPL_DLL CSLSetNameValueSeparator( char ** papszStrList, 
00115                                        const char *pszSeparator );
00116 
00117 #define CPLES_BackslashQuotable 0
00118 #define CPLES_XML               1
00119 #define CPLES_URL               2   
00120 #define CPLES_SQL               3
00121 #define CPLES_CSV               4
00122 
00123 char CPL_DLL *CPLEscapeString( const char *pszString, int nLength, 
00124                                int nScheme );
00125 char CPL_DLL *CPLUnescapeString( const char *pszString, int *pnLength,
00126                                  int nScheme );
00127 
00128 char CPL_DLL *CPLBinaryToHex( int nBytes, const GByte *pabyData );
00129 GByte CPL_DLL *CPLHexToBinary( const char *pszHex, int *pnBytes );
00130 
00131 typedef enum
00132 {
00133     CPL_VALUE_STRING,
00134     CPL_VALUE_REAL,
00135     CPL_VALUE_INTEGER
00136 } CPLValueType;
00137 
00138 CPLValueType CPL_DLL CPLGetValueType(const char* pszValue);
00139 
00140 
00141 
00142 
00143 #define CPL_ENC_LOCALE     ""
00144 #define CPL_ENC_UTF8       "UTF-8"
00145 #define CPL_ENC_UTF16      "UTF-16"
00146 #define CPL_ENC_UCS2       "UCS-2"
00147 #define CPL_ENC_UCS4       "UCS-4"
00148 #define CPL_ENC_ASCII      "ASCII"
00149 #define CPL_ENC_ISO8859_1  "ISO-8859-1"
00150 
00151 char CPL_DLL *CPLRecode( const char *pszSource, 
00152                          const char *pszSrcEncoding, 
00153                          const char *pszDstEncoding );
00154 char CPL_DLL *CPLRecodeFromWChar( const wchar_t *pwszSource, 
00155                                   const char *pszSrcEncoding, 
00156                                   const char *pszDstEncoding );
00157 wchar_t CPL_DLL *CPLRecodeToWChar( const char *pszSource,
00158                                    const char *pszSrcEncoding, 
00159                                    const char *pszDstEncoding );
00160 
00161 CPL_C_END
00162 
00163 
00164 
00165 
00166 
00167 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
00168 
00169 #include <string>
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 #if defined(_MSC_VER) 
00185 # if (_MSC_VER <= 1202) 
00186 #  define MSVC_OLD_STUPID_BEHAVIOUR 
00187 # endif
00188 #endif
00189 
00190 
00191 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
00192     using std::string;
00193 # define std_string string
00194 #else
00195 # define std_string std::string
00196 #endif 
00197 
00198 
00199 #if defined(WIN32CE)
00200 #  pragma warning(disable:4251 4275 4786)
00201 #endif
00202 
00203 
00204 
00205 
00206 class CPL_DLL CPLString : public std_string
00207 {
00208 public:
00209 
00210     
00211     CPLString(void) {}
00212     CPLString( const std::string &oStr ) : std_string( oStr ) {}
00213     CPLString( const char *pszStr ) : std_string( pszStr ) {}
00214     
00215     operator const char* (void) const { return c_str(); }
00216 
00217     char& operator[](std::string::size_type i)
00218     {
00219         return std_string::operator[](i);
00220     }
00221     
00222     const char& operator[](std::string::size_type i) const
00223     {
00224         return std_string::operator[](i);
00225     }
00226 
00227     char& operator[](int i)
00228     {
00229         return std_string::operator[](static_cast<std::string::size_type>(i));
00230     }
00231 
00232     const char& operator[](int i) const
00233     {
00234         return std_string::operator[](static_cast<std::string::size_type>(i));
00235     }
00236 
00237     void Clear() { resize(0); }
00238 
00239     
00240     CPLString &Printf( const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
00241     CPLString &vPrintf( const char *pszFormat, va_list args );
00242     CPLString &FormatC( double dfValue, const char *pszFormat = NULL );
00243     CPLString &Trim();
00244 };
00245 
00246 #endif 
00247 
00248 #endif