# cpl_string.h

Go to the documentation of this file.

    00001 /**********************************************************************
    00002  * $Id: cpl_string.h 21136 2010-11-16 22:47:42Z warmerdam $
    00003  *
    00004  * Name:     cpl_string.h
    00005  * Project:  CPL - Common Portability Library
    00006  * Purpose:  String and StringList functions.
    00007  * Author:   Daniel Morissette, dmorissette@mapgears.com
    00008  *
    00009  **********************************************************************
    00010  * Copyright (c) 1998, Daniel Morissette
    00011  *
    00012  * Permission is hereby granted, free of charge, to any person obtaining a
    00013  * copy of this software and associated documentation files (the "Software"),
    00014  * to deal in the Software without restriction, including without limitation
    00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    00016  * and/or sell copies of the Software, and to permit persons to whom the
    00017  * Software is furnished to do so, subject to the following conditions:
    00018  *
    00019  * The above copyright notice and this permission notice shall be included
    00020  * in all copies or substantial portions of the Software.
    00021  *
    00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    00023  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
    00025  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    00026  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    00027  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    00028  * DEALINGS IN THE SOFTWARE.
    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 char CPL_DLL **CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char** papszOptions);
    00083 int CPL_DLL CSLSave(char **papszStrList, const char *pszFname);
    00084
    00085 char CPL_DLL **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo,
    00086                          char **papszNewLines);
    00087 char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo,
    00088                                const char *pszNewLine);
    00089 char CPL_DLL **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
    00090                          int nNumToRemove, char ***ppapszRetStrings);
    00091 int CPL_DLL CSLFindString( char **, const char * );
    00092 int CPL_DLL CSLPartialFindString( char **papszHaystack,
    00093         const char * pszNeedle );
    00094 int CPL_DLL CSLFindName(char **papszStrList, const char *pszName);
    00095 int CPL_DLL CSLTestBoolean( const char *pszValue );
    00096 int CPL_DLL CSLFetchBoolean( char **papszStrList, const char *pszKey,
    00097                              int bDefault );
    00098
    00099 const char CPL_DLL *CPLSPrintf(const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
    00100 char CPL_DLL **CSLAppendPrintf(char **papszStrList, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3);
    00101 int CPL_DLL CPLVASPrintf(char **buf, const char *fmt, va_list args );
    00102
    00103 const char CPL_DLL *
    00104       CPLParseNameValue(const char *pszNameValue, char **ppszKey );
    00105 const char CPL_DLL *
    00106       CSLFetchNameValue(char **papszStrList, const char *pszName);
    00107 const char CPL_DLL *
    00108       CSLFetchNameValueDef(char **papszStrList, const char *pszName,
    00109                            const char *pszDefault );
    00110 char CPL_DLL **
    00111       CSLFetchNameValueMultiple(char **papszStrList, const char *pszName);
    00112 char CPL_DLL **
    00113       CSLAddNameValue(char **papszStrList,
    00114                       const char *pszName, const char *pszValue);
    00115 char CPL_DLL **
    00116       CSLSetNameValue(char **papszStrList,
    00117                       const char *pszName, const char *pszValue);
    00118 void CPL_DLL CSLSetNameValueSeparator( char ** papszStrList,
    00119                                        const char *pszSeparator );
    00120
    00121 #define CPLES_BackslashQuotable 0
    00122 #define CPLES_XML               1
    00123 #define CPLES_URL               2   /* unescape only for now */
    00124 #define CPLES_SQL               3
    00125 #define CPLES_CSV               4
    00126
    00127 char CPL_DLL *CPLEscapeString( const char *pszString, int nLength,
    00128                                int nScheme );
    00129 char CPL_DLL *CPLUnescapeString( const char *pszString, int *pnLength,
    00130                                  int nScheme );
    00131
    00132 char CPL_DLL *CPLBinaryToHex( int nBytes, const GByte *pabyData );
    00133 GByte CPL_DLL *CPLHexToBinary( const char *pszHex, int *pnBytes );
    00134
    00135 typedef enum
    00136 {
    00137     CPL_VALUE_STRING,
    00138     CPL_VALUE_REAL,
    00139     CPL_VALUE_INTEGER
    00140 } CPLValueType;
    00141
    00142 CPLValueType CPL_DLL CPLGetValueType(const char* pszValue);
    00143
    00144 size_t CPL_DLL CPLStrlcpy(char* pszDest, const char* pszSrc, size_t nDestSize);
    00145 size_t CPL_DLL CPLStrlcat(char* pszDest, const char* pszSrc, size_t nDestSize);
    00146 size_t CPL_DLL CPLStrnlen (const char *pszStr, size_t nMaxLen);
    00147
    00148 /* -------------------------------------------------------------------- */
    00149 /*      RFC 23 character set conversion/recoding API (cpl_recode.cpp).  */
    00150 /* -------------------------------------------------------------------- */
    00151 #define CPL_ENC_LOCALE     ""
    00152 #define CPL_ENC_UTF8       "UTF-8"
    00153 #define CPL_ENC_UTF16      "UTF-16"
    00154 #define CPL_ENC_UCS2       "UCS-2"
    00155 #define CPL_ENC_UCS4       "UCS-4"
    00156 #define CPL_ENC_ASCII      "ASCII"
    00157 #define CPL_ENC_ISO8859_1  "ISO-8859-1"
    00158
    00159 char CPL_DLL *CPLRecode( const char *pszSource,
    00160                          const char *pszSrcEncoding,
    00161                          const char *pszDstEncoding );
    00162 char CPL_DLL *CPLRecodeFromWChar( const wchar_t *pwszSource,
    00163                                   const char *pszSrcEncoding,
    00164                                   const char *pszDstEncoding );
    00165 wchar_t CPL_DLL *CPLRecodeToWChar( const char *pszSource,
    00166                                    const char *pszSrcEncoding,
    00167                                    const char *pszDstEncoding );
    00168 int CPL_DLL CPLIsUTF8(const char* pabyData, int nLen);
    00169 char CPL_DLL *CPLForceToASCII(const char* pabyData, int nLen, char chReplacementChar);
    00170
    00171 CPL_C_END
    00172
    00173 /************************************************************************/
    00174 /*                              CPLString                               */
    00175 /************************************************************************/
    00176
    00177 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
    00178
    00179 #include <string>
    00180
    00181 /*
    00182  * Simple trick to avoid "using" declaration in header for new compilers
    00183  * but make it still working with old compilers which throw C2614 errors.
    00184  *
    00185  * Define MSVC_OLD_STUPID_BEHAVIOUR
    00186  * for old compilers: VC++ 5 and 6 as well as eVC++ 3 and 4.
    00187  */
    00188
    00189 /*
    00190  * Detect old MSVC++ compiler <= 6.0
    00191  * 1200 - VC++ 6.0
    00192  * 1200-1202 - eVC++ 4.0
    00193  */
    00194 #if defined(_MSC_VER)
    00195 # if (_MSC_VER <= 1202)
    00196 #  define MSVC_OLD_STUPID_BEHAVIOUR
    00197 # endif
    00198 #endif
    00199
    00200 /* Avoid C2614 errors */
    00201 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
    00202     using std::string;
    00203 # define gdal_std_string string
    00204 #else
    00205 # define gdal_std_string std::string
    00206 #endif
    00207
    00208 /* Remove annoying warnings in Microsoft eVC++ and Microsoft Visual C++ */
    00209 #if defined(WIN32CE)
    00210 #  pragma warning(disable:4251 4275 4786)
    00211 #endif
    00212
    00213
    00214
    00215
    00216 class CPL_DLL CPLString : public gdal_std_string
    00217 {
    00218 public:
    00219
    00220
    00221     CPLString(void) {}
    00222     CPLString( const std::string &oStr ) : gdal_std_string( oStr ) {}
    00223     CPLString( const char *pszStr ) : gdal_std_string( pszStr ) {}
    00224
    00225     operator const char* (void) const { return c_str(); }
    00226
    00227     char& operator[](std::string::size_type i)
    00228     {
    00229         return gdal_std_string::operator[](i);
    00230     }
    00231
    00232     const char& operator[](std::string::size_type i) const
    00233     {
    00234         return gdal_std_string::operator[](i);
    00235     }
    00236
    00237     char& operator[](int i)
    00238     {
    00239         return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
    00240     }
    00241
    00242     const char& operator[](int i) const
    00243     {
    00244         return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
    00245     }
    00246
    00247     void Clear() { resize(0); }
    00248
    00249     /* There seems to be a bug in the way the compiler count indices... Should be CPL_PRINT_FUNC_FORMAT (1, 2) */
    00250     CPLString &Printf( const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
    00251     CPLString &vPrintf( const char *pszFormat, va_list args );
    00252     CPLString &FormatC( double dfValue, const char *pszFormat = NULL );
    00253     CPLString &Trim();
    00254     CPLString &Recode( const char *pszSrcEncoding, const char *pszDstEncoding );
    00255
    00256 };
    00257
    00258 #endif /* def __cplusplus && !CPL_SUPRESS_CPLUSPLUS */
    00259
    00260 #endif /* _CPL_STRING_H_INCLUDED */

Generated for GDAL by 1.5.6.