- Main Page
- Classes
- Files
- Directories
- Related Pages

- File List
- File Members

# cpl_string.h

Go to the documentation of this file.

    00001 /**********************************************************************
    00002  * $Id: cpl_string.h,v 1.25 2006/04/12 15:10:40 fwarmerdam Exp $
    00003  *
    00004  * Name:     cpl_string.h
    00005  * Project:  CPL - Common Portability Library
    00006  * Purpose:  String and StringList functions.
    00007  * Author:   Daniel Morissette, danmo@videotron.ca
    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  * $Log: cpl_string.h,v $
    00032  * Revision 1.25  2006/04/12 15:10:40  fwarmerdam
    00033  * argument to InsertString should be const
    00034  *
    00035  * Revision 1.24  2006/03/21 20:11:54  fwarmerdam
    00036  * fixup headers a bit
    00037  *
    00038  * Revision 1.23  2006/02/19 21:54:34  mloskot
    00039  * [WINCE] Changes related to Windows CE port of CPL. Most changes are #ifdef wrappers.
    00040  *
    00041  * Revision 1.22  2005/10/13 01:20:16  fwarmerdam
    00042  * added CSLMerge()
    00043  *
    00044  * Revision 1.21  2005/09/14 19:21:17  fwarmerdam
    00045  * binary pointer is const in binarytohex
    00046  *
    00047  * Revision 1.20  2005/08/31 05:08:01  fwarmerdam
    00048  * fixed up std::string use for vc6 compatability
    00049  *
    00050  * Revision 1.19  2005/08/31 03:30:51  fwarmerdam
    00051  * added binarytohex/hextobinary, CPLString
    00052  *
    00053  * Revision 1.18  2005/04/04 15:23:31  fwarmerdam
    00054  * some functions now CPL_STDCALL
    00055  *
    00056  * Revision 1.17  2004/08/16 20:23:46  warmerda
    00057  * added .csv escaping
    00058  *
    00059  * Revision 1.16  2004/07/12 21:50:38  warmerda
    00060  * Added SQL escaping style
    00061  *
    00062  * Revision 1.15  2003/07/17 10:15:40  dron
    00063  * CSLTestBoolean() added.
    00064  *
    00065  * Revision 1.14  2003/03/11 21:33:03  warmerda
    00066  * added URL encode/decode support, untested
    00067  *
    00068  * Revision 1.13  2003/01/30 19:15:55  warmerda
    00069  * added some docs
    00070  **********************************************************************/
    00071
    00072 #ifndef _CPL_STRING_H_INCLUDED
    00073 #define _CPL_STRING_H_INCLUDED
    00074
    00075 #include "cpl_vsi.h"
    00076 #include "cpl_error.h"
    00077 #include "cpl_conv.h"
    00078
    00097 CPL_C_START
    00098
    00099 char CPL_DLL **CSLAddString(char **papszStrList, const char *pszNewString);
    00100 int CPL_DLL CSLCount(char **papszStrList);
    00101 const char CPL_DLL *CSLGetField( char **, int );
    00102 void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList);
    00103 char CPL_DLL **CSLDuplicate(char **papszStrList);
    00104 char CPL_DLL **CSLMerge( char **papszOrig, char **papszOverride );
    00105
    00106 char CPL_DLL **CSLTokenizeString(const char *pszString );
    00107 char CPL_DLL **CSLTokenizeStringComplex(const char *pszString,
    00108                                    const char *pszDelimiter,
    00109                                    int bHonourStrings, int bAllowEmptyTokens );
    00110 char CPL_DLL **CSLTokenizeString2( const char *pszString,
    00111                                    const char *pszDelimeter,
    00112                                    int nCSLTFlags );
    00113
    00114 #define CSLT_HONOURSTRINGS      0x0001
    00115 #define CSLT_ALLOWEMPTYTOKENS   0x0002
    00116 #define CSLT_PRESERVEQUOTES     0x0004
    00117 #define CSLT_PRESERVEESCAPES    0x0008
    00118
    00119 int CPL_DLL CSLPrint(char **papszStrList, FILE *fpOut);
    00120 char CPL_DLL **CSLLoad(const char *pszFname);
    00121 int CPL_DLL CSLSave(char **papszStrList, const char *pszFname);
    00122
    00123 char CPL_DLL **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo,
    00124                          char **papszNewLines);
    00125 char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo,
    00126                                const char *pszNewLine);
    00127 char CPL_DLL **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
    00128                          int nNumToRemove, char ***ppapszRetStrings);
    00129 int CPL_DLL CSLFindString( char **, const char * );
    00130 int CPL_DLL CSLTestBoolean( const char *pszValue );
    00131 int CPL_DLL CSLFetchBoolean( char **papszStrList, const char *pszKey,
    00132                              int bDefault );
    00133
    00134 const char CPL_DLL *CPLSPrintf(char *fmt, ...);
    00135 char CPL_DLL **CSLAppendPrintf(char **papszStrList, char *fmt, ...);
    00136
    00137 const char CPL_DLL *
    00138       CPLParseNameValue(const char *pszNameValue, char **ppszKey );
    00139 const char CPL_DLL *
    00140       CSLFetchNameValue(char **papszStrList, const char *pszName);
    00141 char CPL_DLL **
    00142       CSLFetchNameValueMultiple(char **papszStrList, const char *pszName);
    00143 char CPL_DLL **
    00144       CSLAddNameValue(char **papszStrList,
    00145                       const char *pszName, const char *pszValue);
    00146 char CPL_DLL **
    00147       CSLSetNameValue(char **papszStrList,
    00148                       const char *pszName, const char *pszValue);
    00149 void CPL_DLL CSLSetNameValueSeparator( char ** papszStrList,
    00150                                        const char *pszSeparator );
    00151
    00152 #define CPLES_BackslashQuotable 0
    00153 #define CPLES_XML               1
    00154 #define CPLES_URL               2   /* unescape only for now */
    00155 #define CPLES_SQL               3
    00156 #define CPLES_CSV               4
    00157
    00158 char CPL_DLL *CPLEscapeString( const char *pszString, int nLength,
    00159                                int nScheme );
    00160 char CPL_DLL *CPLUnescapeString( const char *pszString, int *pnLength,
    00161                                  int nScheme );
    00162
    00163 char CPL_DLL *CPLBinaryToHex( int nBytes, const GByte *pabyData );
    00164 GByte CPL_DLL *CPLHexToBinary( const char *pszHex, int *pnBytes );
    00165
    00166 CPL_C_END
    00167
    00168 /************************************************************************/
    00169 /*                              CPLString                               */
    00170 /************************************************************************/
    00171
    00172 #ifdef __cplusplus
    00173
    00174 #include <string>
    00175
    00176 /*
    00177  * Simple trick to avoid "using" declaration in header for new compilers
    00178  * but make it still working with old compilers which throw C2614 errors.
    00179  *
    00180  * Define MSVC_OLD_STUPID_BEHAVIOUR
    00181  * for old compilers: VC++ 5 and 6 as well as eVC++ 3 and 4.
    00182  */
    00183
    00184 /*
    00185  * Detect old MSVC++ compiler <= 6.0
    00186  * 1200 - VC++ 6.0
    00187  * 1200-1202 - eVC++ 4.0
    00188  */
    00189 #if (_MSC_VER <= 1202)
    00190 #  define MSVC_OLD_STUPID_BEHAVIOUR
    00191 #endif
    00192
    00193
    00194 /* Avoid C2614 errors */
    00195 #ifdef MSVC_OLD_STUPID_BEHAVIOUR
    00196     using std::string;
    00197 # define std_string string
    00198 #else
    00199 # define std_string std::string
    00200 #endif
    00201
    00202 /* Remove annoying warnings in eVC++ and VC++ 6.0 */
    00203 #if defined(WIN32CE)
    00204 #  pragma warning(disable:4786)
    00205 #endif
    00206
    00207
    00208
    00209
    00210 class CPL_DLL CPLString : public std_string
    00211 {
    00212 public:
    00213     CPLString(void) {}
    00214     CPLString( const std::string &oStr ) : std_string( oStr ) {}
    00215     CPLString( const char *pszStr ) : std_string( pszStr ) {}
    00216
    00217     operator const char* (void) const { return c_str(); }
    00218
    00219     CPLString &Printf( const char *pszFormat, ... );
    00220     CPLString &vPrintf( const char *pszFormat, va_list args );
    00221 };
    00222
    00223 #endif /* def __cplusplus */
    00224
    00225 #endif /* _CPL_STRING_H_INCLUDED */

Generated for GDAL by 1.4.5.