OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Functions
ossimCplUtil.h File Reference
#include <cstdio>
#include <ossim/base/ossimConstants.h>

Go to the source code of this file.

Functions

OSSIMDLLEXPORT char ** ossimCSLTokenizeString (const char *pszString)
 
OSSIMDLLEXPORT char ** ossimCSLTokenizeStringComplex (const char *pszString, const char *pszDelimiter, int bHonourStrings, int bAllowEmptyTokens)
 
OSSIMDLLEXPORT char ** ossimCSLTokenizeString2 (const char *pszString, const char *pszDelimeter, int nCSLTFlags)
 
OSSIMDLLEXPORT int ossimCSLCount (char **papszStrList)
 
OSSIMDLLEXPORT void ossimCSLDestroy (char **papszStrList)
 
OSSIMDLLEXPORT void * ossimCPLRealloc (void *pData, size_t nNewSize)
 

Function Documentation

◆ ossimCPLRealloc()

OSSIMDLLEXPORT void* ossimCPLRealloc ( void *  pData,
size_t  nNewSize 
)

Definition at line 283 of file ossimCplUtil.cpp.

Referenced by ossimDDFModule::AddCloneRecord(), ossimDDFModule::AddField(), ossimCSLTokenizeString2(), and ossimDDFRecord::ResizeField().

285 {
286  void *pReturn;
287 
288  if ( nNewSize == 0 )
289  {
290  free(pData);
291  return NULL;
292  }
293 
294  if( pData == NULL )
295  pReturn = malloc( nNewSize );
296  else
297  pReturn = realloc( pData, nNewSize );
298 
299  return pReturn;
300 }

◆ ossimCSLCount()

OSSIMDLLEXPORT int ossimCSLCount ( char **  papszStrList)

Definition at line 245 of file ossimCplUtil.cpp.

Referenced by ossimDDFFieldDefn::BuildSubfields().

246 {
247  int nItems=0;
248 
249  if (papszStrList)
250  {
251  while(*papszStrList != NULL)
252  {
253  nItems++;
254  papszStrList++;
255  }
256  }
257 
258  return nItems;
259 }

◆ ossimCSLDestroy()

OSSIMDLLEXPORT void ossimCSLDestroy ( char **  papszStrList)

Definition at line 266 of file ossimCplUtil.cpp.

Referenced by ossimDDFFieldDefn::ApplyFormats(), and ossimDDFFieldDefn::BuildSubfields().

267 {
268  char **papszPtr;
269 
270  if (papszStrList)
271  {
272  papszPtr = papszStrList;
273  while(*papszPtr != NULL)
274  {
275  free(*papszPtr);
276  papszPtr++;
277  }
278 
279  free(papszStrList);
280  }
281 }

◆ ossimCSLTokenizeString()

OSSIMDLLEXPORT char** ossimCSLTokenizeString ( const char *  pszString)

Definition at line 86 of file ossimCplUtil.cpp.

References OSSIM_CSLT_HONOURSTRINGS, and ossimCSLTokenizeString2().

87 {
88  return ossimCSLTokenizeString2( pszString, " ", OSSIM_CSLT_HONOURSTRINGS );
89 }
#define OSSIM_CSLT_HONOURSTRINGS
char ** ossimCSLTokenizeString2(const char *pszString, const char *pszDelimiters, int nCSLTFlags)

◆ ossimCSLTokenizeString2()

OSSIMDLLEXPORT char** ossimCSLTokenizeString2 ( const char *  pszString,
const char *  pszDelimeter,
int  nCSLTFlags 
)

Definition at line 119 of file ossimCplUtil.cpp.

References OSSIM_CSLT_ALLOWEMPTYTOKENS, OSSIM_CSLT_HONOURSTRINGS, OSSIM_CSLT_PRESERVEESCAPES, OSSIM_CSLT_PRESERVEQUOTES, and ossimCPLRealloc().

Referenced by ossimCSLTokenizeString(), and ossimCSLTokenizeStringComplex().

123 {
124  char **papszRetList = NULL;
125  int nRetMax = 0, nRetLen = 0;
126  char *pszToken;
127  int nTokenMax, nTokenLen;
128  int bHonourStrings = (nCSLTFlags & OSSIM_CSLT_HONOURSTRINGS);
129  int bAllowEmptyTokens = (nCSLTFlags & OSSIM_CSLT_ALLOWEMPTYTOKENS);
130 
131  pszToken = (char *) calloc(10,1);
132  nTokenMax = 10;
133 
134  while( pszString != NULL && *pszString != '\0' )
135  {
136  int bInString = false;
137 
138  nTokenLen = 0;
139 
140  /* Try to find the next delimeter, marking end of token */
141  for( ; *pszString != '\0'; pszString++ )
142  {
143 
144  /* End if this is a delimeter skip it and break. */
145  if( !bInString && strchr(pszDelimiters, *pszString) != NULL )
146  {
147  pszString++;
148  break;
149  }
150 
151  /* If this is a quote, and we are honouring constant
152  strings, then process the constant strings, with out delim
153  but don't copy over the quotes */
154  if( bHonourStrings && *pszString == '"' )
155  {
156  if( nCSLTFlags & OSSIM_CSLT_PRESERVEQUOTES )
157  {
158  pszToken[nTokenLen] = *pszString;
159  nTokenLen++;
160  }
161 
162  if( bInString )
163  {
164  bInString = false;
165  continue;
166  }
167  else
168  {
169  bInString = true;
170  continue;
171  }
172  }
173 
174  /* Within string constants we allow for escaped quotes, but
175  in processing them we will unescape the quotes */
176  if( bInString && pszString[0] == '\\' && pszString[1] == '"' )
177  {
178  if( nCSLTFlags & OSSIM_CSLT_PRESERVEESCAPES )
179  {
180  pszToken[nTokenLen] = *pszString;
181  nTokenLen++;
182  }
183 
184  pszString++;
185  }
186 
187  /* Within string constants a \\ sequence reduces to \ */
188  else if( bInString
189  && pszString[0] == '\\' && pszString[1] == '\\' )
190  {
191  if( nCSLTFlags & OSSIM_CSLT_PRESERVEESCAPES )
192  {
193  pszToken[nTokenLen] = *pszString;
194  nTokenLen++;
195  }
196  pszString++;
197  }
198 
199  if( nTokenLen >= nTokenMax-3 )
200  {
201  nTokenMax = nTokenMax * 2 + 10;
202  pszToken = (char *) ossimCPLRealloc( pszToken, nTokenMax );
203  }
204 
205  pszToken[nTokenLen] = *pszString;
206  nTokenLen++;
207  }
208 
209  pszToken[nTokenLen] = '\0';
210 
211  /*
212  * If the last token is an empty token, then we have to catch
213  * it now, otherwise we won't reenter the loop and it will be lost.
214  */
215 
216  if( (pszToken[0] != '\0' || bAllowEmptyTokens)
217  || (*pszString == '\0' && bAllowEmptyTokens
218  && strchr(pszDelimiters, *(pszString-1)) ) )
219  {
220  if( nRetLen >= nRetMax - 1 )
221  {
222  nRetMax = nRetMax * 2 + 10;
223  papszRetList = (char **)
224  ossimCPLRealloc(papszRetList, sizeof(char*) * nRetMax );
225  }
226 
227  papszRetList[nRetLen++] = strdup( pszToken );
228  papszRetList[nRetLen] = NULL;
229  }
230  }
231 
232  if( papszRetList == NULL )
233  papszRetList = (char **) calloc(sizeof(char *),1);
234 
235  free( pszToken );
236 
237  return papszRetList;
238 }
#define OSSIM_CSLT_PRESERVEQUOTES
#define OSSIM_CSLT_PRESERVEESCAPES
#define OSSIM_CSLT_HONOURSTRINGS
#define OSSIM_CSLT_ALLOWEMPTYTOKENS
void * ossimCPLRealloc(void *pData, size_t nNewSize)

◆ ossimCSLTokenizeStringComplex()

OSSIMDLLEXPORT char** ossimCSLTokenizeStringComplex ( const char *  pszString,
const char *  pszDelimiter,
int  bHonourStrings,
int  bAllowEmptyTokens 
)

Definition at line 97 of file ossimCplUtil.cpp.

References OSSIM_CSLT_ALLOWEMPTYTOKENS, OSSIM_CSLT_HONOURSTRINGS, and ossimCSLTokenizeString2().

Referenced by ossimDDFFieldDefn::ApplyFormats(), and ossimDDFFieldDefn::BuildSubfields().

102 {
103  int nFlags = 0;
104 
105  if( bHonourStrings )
106  nFlags |= OSSIM_CSLT_HONOURSTRINGS;
107  if( bAllowEmptyTokens )
108  nFlags |= OSSIM_CSLT_ALLOWEMPTYTOKENS;
109 
110  return ossimCSLTokenizeString2( pszString, pszDelimiters, nFlags );
111 }
#define OSSIM_CSLT_HONOURSTRINGS
#define OSSIM_CSLT_ALLOWEMPTYTOKENS
char ** ossimCSLTokenizeString2(const char *pszString, const char *pszDelimiters, int nCSLTFlags)