OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimString.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Garrett Potts
8 //
9 // Description: This class extends the stl's string class.
10 //
11 //********************************************************************
12 // $Id: ossimString.cpp 22160 2013-02-25 12:09:35Z gpotts $
13 
14 #include <cctype> /* for toupper */
15 #include <cstdlib> /* for getenv() */
16 #include <stack>
17 #include <iostream>
18 #include <iomanip>
19 #include <sstream>
20 #include <stdlib.h>
21 #include <algorithm>
22 #include <ossim/base/ossimCommon.h>
23 #include <ossim/base/ossimString.h>
24 #include <ossim/base/ossimRegExp.h>
25 #include <ossim/base/ossimTrace.h>
27 
28 static ossimTrace traceDebug("ossimString:debug");
29 
30 #ifdef OSSIM_ID_ENABLED
31 static char OSSIM_ID[] = "$Id: ossimString.cpp 22160 2013-02-25 12:09:35Z gpotts $";
32 #endif
33 
35 {
36  std::string s = aString.string();
37 
38  std::string::iterator eachCharacter = s.begin();
39  while(eachCharacter != s.end())
40  {
41  *eachCharacter = toupper(*eachCharacter);
42  eachCharacter++;
43  }
44 
45  return s;
46 }
47 
49 {
50  std::string s = aString.m_str;
51 
52  std::string::iterator eachCharacter = s.begin();
53  while(eachCharacter != s.end())
54  {
55  *eachCharacter = tolower(*eachCharacter);
56  ++eachCharacter;
57  }
58 
59  return ossimString(s);
60 }
61 
63 {
64  std::string::iterator eachCharacter = m_str.begin();
65  while(eachCharacter != m_str.end())
66  {
67  *eachCharacter = toupper(*eachCharacter);
68  ++eachCharacter;
69  }
70 
71  return *this;
72 }
73 
75 {
76  ossimString result(*this);
77  result.upcase();
78  return result;
79 }
80 
82 {
83  std::string::iterator eachCharacter = m_str.begin();
84  while(eachCharacter != m_str.end())
85  {
86  *eachCharacter = tolower(*eachCharacter);
87  ++eachCharacter;
88  }
89 
90  return *this;
91 }
92 
94 {
95  ossimString result(*this);
96  result.downcase();
97  return result;
98 }
99 
101 {
102  char *result = 0;
103 
104  if(length() == 0)
105  {
106  result = new char[1];
107  result[0] = '\0';
108  }
109  else
110  {
111  ossim_uint32 index = 0;
112  ossim_uint32 len = (ossim_uint32)m_str.length();
113  result = new char[len+1];
114  const char* sourceString = m_str.c_str();
115 
116  while(index < len)
117  {
118  result[index] = sourceString[index];
119  ++index;
120  }
121  result[len] = '\0';
122  }
123  return result;
124 }
125 
126 ossimString ossimString::stripLeading(const ossimString &value, char characterToStrip)
127 {
128  std::string s;
129  ossimString::const_iterator stringIter = value.m_str.begin();
130 
131  while((*stringIter == characterToStrip)&&(stringIter!=value.m_str.end()))
132  {
133  ++stringIter;
134  }
135 
136  while(stringIter != value.m_str.end())
137  {
138  s += *stringIter;
139  ++stringIter;
140  }
141 
142  return ossimString(s);
143 }
144 
146  const ossimString &replacementValue,
147  bool replaceAll)const
148 {
149  std::string result = m_str;
150 
151  size_type pos = result.find(searchKey.m_str);
152 
153  if (pos == std::string::npos) return result; // Search key not found.
154 
155  if(replaceAll)
156  {
157  while(pos != std::string::npos)
158  {
159  result.replace(pos, searchKey.m_str.size(), replacementValue.m_str.c_str());
160  pos = result.find(searchKey.m_str, pos+replacementValue.m_str.size());
161  }
162  }
163  else // Replace only the first instance.
164  {
165  result.replace(pos, searchKey.m_str.size(), replacementValue.m_str.c_str());
166  }
167 
168  return ossimString(result);
169 }
170 
172  const ossimString &replacementValue,
173  bool replaceAll)
174 {
175  size_type pos = m_str.find(searchKey.m_str);
176 
177  if (pos == std::string::npos) return *this; // Search key not found.
178 
179  if(replaceAll)
180  {
181  while(pos < m_str.size())
182  {
183  m_str.replace(pos, searchKey.m_str.size(), replacementValue.m_str.c_str());
184  pos = find(searchKey.m_str, pos+replacementValue.m_str.size());
185  }
186  }
187  else // Replace only the first instance.
188  {
189  m_str.replace(pos, searchKey.m_str.size(), replacementValue.m_str.c_str());
190  }
191 
192  return *this;
193 }
194 
195 ossimString ossimString::trim(const ossimString& valueToTrim) const
196 {
197  ossimString tempString(*this);
198 
199  return tempString.trim(valueToTrim);
200 }
201 
203 {
204  if(m_str.size() == 0) return *this;
205  if(valueToTrim.empty()) return *this;
206  iterator startPos = (*this).begin();
207  iterator endPos = (*this).begin() + ((*this).size()-1);
208 
209  while( ( startPos != (*this).end() ) &&
210  (std::find(valueToTrim.begin(),
211  valueToTrim.end(),
212  *startPos)!=valueToTrim.end()) ) ++startPos;
213 
214  if(startPos == (*this).end())
215  {
216  *this = "";
217  return *this;
218  }
219 
220  while( (endPos!=startPos)&& (std::find(valueToTrim.begin(),
221  valueToTrim.end(),
222  *endPos)!=valueToTrim.end())) --endPos;
223 
224  *this = ossimString(startPos, endPos+1);
225 
226  return *this;
227 }
228 
229 ossimString ossimString::beforePos(std::string::size_type pos)const
230 {
231  return substr(0, pos);
232 }
233 
234 ossimString ossimString::afterPos(std::string::size_type pos)const
235 {
236  ossimString result = *this;
237 
238  if(pos < length())
239  {
240  result.erase(0, pos+1);
241  }
242  else
243  {
244  return "";
245  }
246 
247  return result;
248 
249 }
250 
251 std::vector<ossimString> ossimString::explode(const ossimString& delimeter) const
252 {
253  ossimString exp_str = *this;
254  std::vector<ossimString> result;
255  char* tokenPtr = strtok((char*)exp_str.c_str(), (char*)delimeter.c_str());
256 
257  while(tokenPtr != NULL)
258  {
259  result.push_back(tokenPtr);
260  tokenPtr = strtok(NULL, delimeter.c_str());
261  }
262 
263  return result;
264 }
265 
267 {
268  ossimString result(*this);
269  std::stack<ossim_uint32> startChars;
270  ossimRegExp regExpStart("\\$\\(");
271 
272  if(regExpStart.find(result.c_str()))
273  {
274  startChars.push(regExpStart.start());
275  while(!startChars.empty())
276  {
277  ossim_uint32 offset = startChars.top() + 2; // skip over the $(
278 
279  // We will replace like a stack by looking at the right most $(
280  //
281  if(regExpStart.find(result.c_str()+offset))
282  {
283  // maintain absolute offset to the original string
284  startChars.push(regExpStart.start()+offset);
285  }
286  else
287  {
288  // now look for a closing ) for the stating $(
289  ossimRegExp regExpEnd("\\)");
290  if(regExpEnd.find(result.c_str()+startChars.top()))
291  {
292  ossimString envVarStr(result.begin()+startChars.top()+2,
293  result.begin()+startChars.top()+regExpEnd.start());
294  const char* lookup = getenv( envVarStr.c_str() );
295  if ( lookup )
296  {
297  result.replace(result.begin()+startChars.top(),
298  result.begin()+startChars.top()+regExpEnd.start()+1,
299  ossimString(lookup));
300  }
301  else
302  {
303  if(traceDebug())
304  {
306  << "In member function ossimString::expandEnvironmentVariable() "
307  << "\n\tERROR: Environment variable("
308  << envVarStr.c_str()
309  << ") not found!"
310  << std::endl;
311  }
312  result.replace(result.begin()+startChars.top(),
313  result.begin()+startChars.top()+regExpEnd.start()+1,
314  "");
315  }
316  }
317  startChars.pop();
318  }
319  }
320  }
321 
322 
323  return result;
324 }
325 
326 //---
327 // Regular expression pattern utilities
328 //---
329 
330 ossimString ossimString::beforeRegExp(const char *regularExpressionPattern) const
331 {
332  ossimRegExp anExpression;
333 
334  anExpression.compile(regularExpressionPattern);
335 
336  if(anExpression.find(c_str()))
337  {
338  if (anExpression.start() > 0)
339  {
340  return substr(0, anExpression.start());
341  }
342  }
343 
344  return ossimString("");
345 }
346 
347 ossimString ossimString::fromRegExp(const char *regularExpressionPattern) const
348 {
349  ossimRegExp anExpression;
350 
351  anExpression.compile(regularExpressionPattern);
352 
353  if(anExpression.find(c_str()))
354  {
355  if (anExpression.start() < size())
356  {
357  return substr(anExpression.start(), (size()-anExpression.start()));
358  }
359  }
360 
361  return ossimString("");
362 }
363 
364 ossimString ossimString::afterRegExp(const char *regularExpressionPattern) const
365 {
366  ossimRegExp anExpression;
367 
368  anExpression.compile(regularExpressionPattern);
369 
370  if(anExpression.find(c_str()))
371  {
372  if (anExpression.end() < size())
373  {
374  return substr(anExpression.end(), (size()-anExpression.end()));
375  }
376  }
377 
378  return ossimString("");
379 }
380 
381 ossimString ossimString::match(const char *regularExpressionPattern) const
382 {
383  ossimRegExp anExpression;
384 
385  anExpression.compile(regularExpressionPattern);
386 
387  if((anExpression.find(this->c_str())) &&
388  (anExpression.start() !=anExpression.end()))
389  {
390  return this->substr(anExpression.start(),
391  anExpression.end() - anExpression.start() );
392  }
393 
394 
395  return ossimString("");
396 }
397 
398 ossimString ossimString::replaceAllThatMatch(const char *regularExpressionPattern,
399  const char *value) const
400 {
401  ossimString result = *this;
402  ossimRegExp anExpression;
403  std::string::size_type offset = 0;
404  std::string::size_type valueLength = ossimString(value).length();
405  anExpression.compile(regularExpressionPattern);
406  if(!anExpression.is_valid())
407  {
408  return *this;
409  }
410  while(anExpression.find(result.c_str()+offset))
411  {
412  if(anExpression.start() < anExpression.end())
413  {
414  result.replace(anExpression.start() + offset,
415  anExpression.end()-anExpression.start(),
416  value);
417  offset += anExpression.start() + valueLength;
418  }
419  else
420  {
421  break;
422  }
423  }
424 
425  return result;
426 }
427 
428 ossimString ossimString::replaceStrThatMatch(const char *regularExpressionPattern,
429  const char *value) const
430 {
431  ossimString result = *this;
432  ossimRegExp anExpression;
433  anExpression.compile(regularExpressionPattern);
434  if(!anExpression.is_valid())
435  {
436  return *this;
437  }
438  if(anExpression.find(result.c_str()))
439  {
440  if(anExpression.start() < anExpression.end())
441  {
442  result.replace(anExpression.start(),
443  anExpression.end()-anExpression.start(),
444  value);
445  }
446  }
447 
448  return result;
449 }
450 
452 {
453  ossimString s = c_str();
454  s = s.trim();
455  if (s.empty())
456  {
457  return false;
458  }
459 
460  s = s.downcase();
461  if ( (s == "true") ||
462  (s == "yes") ||
463  (s == "y") ||
464  (s == "1") )
465  {
466  return true;
467  }
468  else if ( (s == "false") ||
469  (s == "no") ||
470  (s == "n") ||
471  (s == "0") )
472  {
473  return false;
474 
475  }
476  else if (toInt32())
477  {
478  return true;
479  }
480 
481  return false;
482 }
483 
484 bool ossimString::toBool(const ossimString& aString)
485 {
486  // Check for true or false, yes or no, y or n, and 1 or 0...
487  ossimString s = aString;
488  if (s.empty())
489  {
490  return false;
491  }
492  s.downcase();
493  if ( (s == "true") ||
494  (s == "yes") ||
495  (s == "y") ||
496  (s == "1") )
497  {
498  return true;
499  }
500  else if ( (s == "false") ||
501  (s == "no") ||
502  (s == "n") ||
503  (s == "0") )
504  {
505  return false;
506 
507  }
508  else if (aString.toInt32())
509  {
510  return true;
511  }
512 
513  return false;
514 }
515 
517 {
518  // Note the std::istringstream::operator>> does not work with unsigned 8 bit.
519  ossim_uint16 i = 0;
520  if (!empty())
521  {
523  is >> i;
524 #if 0
525  // if extraction fails, value (0) is left unmodified until C++11, or
526  // is set to zero (C++11) => no test required!
527  if(is.fail())
528  {
529  i = 0;
530  }
531 #endif
532  }
533  return static_cast<ossim_uint8>(i);
534 }
535 
537 {
538  return aString.toUInt8();
539 }
540 
542 {
543  int i = 0;
544  if (!empty())
545  {
547  is >> i;
548 #if 0
549  // if extraction fails, value (0) is left unmodified until C++11, or
550  // is set to zero (C++11) => no test required!
551  if(is.fail())
552  {
553  i = 0;
554  }
555 #endif
556  }
557  return i;
558 }
559 
560 int ossimString::toInt(const ossimString& aString)
561 {
562  return aString.toInt();
563 }
564 
566 {
567  ossim_int16 i = 0;
568  if (!empty())
569  {
571  is >> i;
572 #if 0
573  // if extraction fails, value (0) is left unmodified until C++11, or
574  // is set to zero (C++11) => no test required!
575  if(is.fail())
576  {
577  i = 0;
578  }
579 #endif
580  }
581  return i;
582 }
583 
585 {
586  return aString.toInt16();
587 }
588 
590 {
591  ossim_uint16 i = 0;
592  if (!empty())
593  {
595  is >> i;
596 #if 0
597  // if extraction fails, value (0) is left unmodified until C++11, or
598  // is set to zero (C++11) => no test required!
599  if(is.fail())
600  {
601  i = 0;
602  }
603 #endif
604  }
605  return i;
606 }
607 
609 {
610  return aString.toUInt16();
611 }
612 
614 {
615  ossim_int32 i = 0;
616  if (!empty())
617  {
619  is >> i;
620 #if 0
621  // if extraction fails, value (0) is left unmodified until C++11, or
622  // is set to zero (C++11) => no test required!
623  if(is.fail())
624  {
625  i = 0;
626  }
627 #endif
628  }
629  return i;
630 }
631 
633 {
634  return aString.toInt32();
635 }
636 
638 {
639  ossim_uint32 i = 0;
640  if (!empty())
641  {
643  is >> i;
644 #if 0
645  // if extraction fails, value (0) is left unmodified until C++11, or
646  // is set to zero (C++11) => no test required!
647  if(is.fail())
648  {
649  i = 0;
650  }
651 #endif
652  }
653  return i;
654 }
655 
657 {
658  return aString.toUInt32();
659 }
660 
662 {
663  ossim_int64 i = 0;
664  if (!empty())
665  {
667  is >> i;
668 #if 0
669  // if extraction fails, value (0) is left unmodified until C++11, or
670  // is set to zero (C++11) => no test required!
671  if(is.fail())
672  {
673  i = 0;
674  }
675 #endif
676  }
677  return i;
678 }
679 
681 {
682  return aString.toInt64();
683 }
684 
686 {
687  ossim_uint64 i = 0;
688  if (!empty())
689  {
691  is >> i;
692 #if 0
693  // if extraction fails, value (0) is left unmodified until C++11, or
694  // is set to zero (C++11) => no test required!
695  if(is.fail())
696  {
697  i = 0;
698  }
699 #endif
700  }
701  return i;
702 }
703 
705 {
706  return aString.toUInt64();
707 }
708 
710 {
711  ossim_int64 result = toInt64();
712  if((result != 0)&&size()>0)
713  {
714  ossimString byteType = *(begin()+(size()-1));
715  byteType.upcase();
716  if ( byteType == "K")
717  {
718  result *= static_cast<ossim_int64>(1024);
719  }
720  else if ( byteType == "M")
721  {
722  result *= static_cast<ossim_int64>(1048576);
723  }
724  else if ( byteType == "G")
725  {
726  result *= static_cast<ossim_int64>(1073741824);
727  }
728  else if( byteType == "T")
729  {
730  // to avoid possible integer size warnings
731  // we will start with a number that is 1 gig
732  // for it fits within a standard integer then
733  // force 64 bit mutliplication.
734  // Will do it like this for I do not know the
735  // outcome for other compilers.
736  result *= static_cast<ossim_int64>(1073741824);
737  result *= static_cast<ossim_int64>(1024);
738  }
739  }
740 
741  return result;
742 }
743 
745 {
746  return aString.memoryUnitToInt64();
747 }
748 
750 {
751  long i = 0;
752  if (!empty())
753  {
755  is >> i;
756 #if 0
757  // if extraction fails, value (0) is left unmodified until C++11, or
758  // is set to zero (C++11) => no test required!
759  if(is.fail())
760  {
761  i = 0;
762  }
763 #endif
764  }
765  return i;
766 }
767 
768 long ossimString::toLong(const ossimString& aString)
769 {
770  return aString.toLong();
771 }
772 
773 unsigned long ossimString::toULong()const
774 {
775  unsigned long i = 0;
776  if (!empty())
777  {
779  is >> i;
780 #if 0
781  // if extraction fails, value (0) is left unmodified until C++11, or
782  // is set to zero (C++11) => no test required!
783  if(is.fail())
784  {
785  i = 0;
786  }
787 #endif
788  }
789  return i;
790 }
791 
792 unsigned long ossimString::toULong(const ossimString& aString)
793 {
794  return aString.toULong();
795 }
796 
798 {
799  if(contains("nan"))
800  {
801  return ossim::nan();
802  }
803  ossim_float32 d = 0.0;
804  // this part is core dumping under mingw in ossimPlanet.
805  // There is a possibility that this isn't a thread safe implementation
806  // in mingw stl. Let's resort back to atof for now
807 
808 #if 0
809  d = (ossim_float32)atof(c_str());
810 #else
811  if (!empty())
812  {
813  std::istringstream is(m_str); // std::istringstream takes a basic_string
814  is >> d;
815 #if 0
816  // if extraction fails, value (0.0) is left unmodified until C++11, or
817  // is set to zero (C++11) => no test required!
818  if(is.fail())
819  {
820  d = 0.0;
821  }
822 #endif
823  }
824 #endif
825  return d;
826 }
827 
829 {
830  return aString.toFloat32();
831 }
832 
834 {
835  if(contains("nan"))
836  {
837  return ossim::nan();
838  }
839  ossim_float64 d = 0.0;
840  // this part is core dumping under mingw in ossimPlanet.
841  // There is a possibility that this isn't a thread safe implementation
842  // in mingw stl. Let's resort back to atof for now
843 
844 #if 0
845  d = (ossim_float64)atof(c_str());
846 #endif
847 #if 1
848  if (!empty())
849  {
850  std::istringstream is(m_str); // std::istringstream takes a basic_string
851  is >> d;
852 #if 0
853  // if extraction fails, value (0.0) is left unmodified until C++11, or
854  // is set to zero (C++11) => no test required!
855  if(is.fail())
856  {
857  d = 0.0;
858  }
859 #endif
860  }
861 #endif
862  return d;
863 }
864 
866 {
867  return aString.toFloat64();
868 }
869 
871 {
872  if(contains("nan"))
873  {
874  return ossim::nan();
875  }
876  double d = 0.0;
877 
878  // this part is core dumping under mingw in ossimPlanet.
879  // There is a possibility that this isn't a thread safe implementation
880  // in mingw stl. Let's resort back to atof for now
881 
882  if (!empty())
883  {
884 #if 0
885  d = atof(c_str());
886 #else
887  std::istringstream is(m_str); // std::istringstream takes a basic_string
888  is >> d;
889 #if 0
890  // if extraction fails, value (0.0) is left unmodified until C++11, or
891  // is set to zero (C++11) => no test required!
892  if(is.fail())
893  {
894  d = 0.0;
895  }
896 #endif
897  }
898 #endif
899  return d;
900 }
901 
902 double ossimString::toDouble(const ossimString& aString)
903 {
904  return aString.toDouble();
905 }
906 
908 {
910  if (aValue)
911  s << "true";
912  else
913  s << "false";
914  ossimString result(s.str());
915  return result;
916 }
917 
919 {
921  s << aValue;
922  ossimString result(s.str());
923  return result;
924 }
925 
927 {
929  s << aValue;
930  ossimString result(s.str());
931  return result;
932 }
933 
935 {
937  s << aValue;
938  ossimString result(s.str());
939  return result;
940 }
941 
943 {
945  s << aValue;
946  ossimString result(s.str());
947  return result;
948 }
949 
951 {
953  s << aValue;
954  ossimString result(s.str());
955  return result;
956 }
957 
959 {
961  s << aValue;
962  ossimString result(s.str());
963  return result;
964 }
965 
967  ossim_int32 precision,
968  bool fixed)
969 {
970  if ( ossim::isnan(aValue) )
971  {
972  return ossimString("nan");
973  }
974 
976  s << std::setprecision(precision);
977 
978  if (fixed)
979  {
980  s << std::setiosflags(std::ios::fixed);
981  }
982 
983  s << aValue;
984 
985  return ossimString(s.str());
986 }
987 
989  ossim_int32 precision,
990  bool fixed)
991 {
992  if ( ossim::isnan(aValue) )
993  {
994  return ossimString("nan");
995  }
996 
998  s << std::setprecision(precision);
999 
1000  if (fixed)
1001  {
1002  s << std::setiosflags(std::ios::fixed);
1003  }
1004 
1005  s << aValue;
1006 
1007  return ossimString(s.str());
1008 }
1009 
1011  std::string::size_type pos)const
1012 {
1013  if(*this == "") return ossimString();
1014 
1015  size_type last = find(str.c_str(), pos);
1016  if(last >= std::string::npos) return *this;
1017 
1018  return ossimString( substr(0, last) );
1019 }
1020 
1022  std::string::size_type pos)const
1023 {
1024  size_type last = find(str.c_str(), pos);
1025  if (last >= std::string::npos) return ossimString();
1026 
1027  return ossimString( substr(last+str.length()) );
1028 }
1029 
1030 //*************************************************************************************************
1031 // Splits this string into a vector of strings (fields) using the delimiter list specified.
1032 // If a delimiter is encountered at the beginning or the end of this, or two delimiters are
1033 // contiguous, a blank field is inserted in the vector, unless skipBlankFields is true.
1034 //*************************************************************************************************
1035 void ossimString::split(std::vector<ossimString>& result,
1036  const ossimString& separatorList,
1037  bool skipBlankFields)const
1038 {
1039  if(this->empty()) return;
1040 
1041  std::string::const_iterator iterStart = m_str.begin();
1042  std::string::const_iterator iterCurrent = m_str.begin();
1043 
1044  while(iterCurrent != m_str.end())
1045  {
1046  if(std::find(separatorList.m_str.begin(), separatorList.m_str.end(), *iterCurrent) != separatorList.m_str.end())
1047  {
1048  if(iterStart == iterCurrent)
1049  {
1050  if(!skipBlankFields)
1051  {
1052  result.push_back(ossimString());
1053  }
1054  }
1055  else
1056  {
1057  result.push_back(ossimString(iterStart, iterCurrent));
1058  }
1059 
1060  ++iterCurrent;
1061  iterStart = iterCurrent;
1062  }
1063  else
1064  {
1065  ++iterCurrent;
1066  }
1067  }
1068  if(iterStart!=iterCurrent)
1069  {
1070  result.push_back(ossimString(iterStart, iterCurrent));
1071  }
1072 
1073 #if 0
1074 // result = split(separatorList);
1075  ossimString copyString = *this;
1076 
1077  char* s = strtok(const_cast<char*>(copyString.c_str()),
1078  separatorList.c_str());
1079 
1080  for(std::string::size_type i = 0; i < separatorList.size(); ++ i)
1081  {
1082  if (((*(this->begin())) == separatorList.c_str()[i]) && !skipBlankFields)
1083  result.push_back("");
1084  }
1085  while(s)
1086  {
1087  result.push_back(ossimString(s));
1088  if ((*s != 0) || !skipBlankFields)
1089  s = strtok(NULL, separatorList.c_str());
1090  }
1091  for(std::string::size_type i = 0; i < separatorList.size(); ++ i)
1092  {
1093  if (((*(this->end()-1)) == separatorList.c_str()[i]) && !skipBlankFields)
1094  result.push_back("");
1095  }
1096 #endif
1097 }
1098 
1099 std::vector<ossimString> ossimString:: split(const ossimString& separatorList,
1100  bool skipBlankFields)const
1101 {
1102  std::vector<ossimString> result;
1103 
1104  split(result, separatorList, skipBlankFields);
1105 
1106  return result;
1107 }
1108 
1109 const ossimString& ossimString::join(const std::vector<ossimString>& stringList,
1110  const ossimString& separator)
1111 {
1112  *this = "";
1113  if(stringList.size())
1114  {
1115  for(long i = 0; i < ((long)stringList.size()-1); ++i)
1116  {
1117  *this += stringList[i];
1118  *this += separator;
1119  }
1120  *this += stringList[stringList.size()-1];
1121  }
1122 
1123  return *this;
1124 }
1125 
1127 {
1129  ossimString result;
1130  while(iter != end())
1131  {
1132  ossim_uint8 c = *iter;
1133 
1134  if(c > 47 && c < 58)
1135  {
1136  result += c;
1137  }
1138  else if(c > 64 && c < 91)
1139  {
1140  result += c;
1141  }
1142  else if(c > 96 && c < 123)
1143  {
1144  result+=c;
1145  }
1146  else if (c == 32)
1147  {
1148  result+="+";
1149  }
1150  else
1151  {
1152  result += ("%" + ossimHexString(c));
1153  }
1154 
1155  ++iter;
1156  }
1157 
1158  return result;
1159 
1160 }
1161 
1163 {
1164 #ifdef OSSIM_ID_ENABLED
1165  return ossimString(OSSIM_ID);
1166 #endif
1167  return ossimString("");
1168 }
1169 
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossimString match(const char *regularExpressionPattern) const
Returns from found pattern to end of pattern.
std::string::iterator iterator
Definition: ossimString.h:27
const ossimString & join(const std::vector< ossimString > &stringList, const ossimString &separator)
ossimString beforeRegExp(const char *regularExpressionPattern) const
Returns from start of string up to but not including found pattern.
ossim_uint8 toUInt8() const
std::string m_str
Definition: ossimString.h:733
float ossim_float32
ossimString afterPos(std::string::size_type pos) const
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
bool contains(char aChar) const
Definition: ossimString.h:58
static ossimString toString(bool aValue)
Numeric to string methods.
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
std::string::const_iterator const_iterator
Definition: ossimString.h:26
char * stringDup() const
ossim_uint32 toUInt32() const
unsigned short ossim_uint16
std::string::size_type size_type
Definition: ossimString.h:28
std::string::iterator end()
Definition: ossimString.h:423
ossimString fromRegExp(const char *regularExpressionPattern) const
Returns from position of found pattern to end of string.
ossim_int32 toInt32() const
ossimString afterRegExp(const char *regularExpressionPattern) const
Returns from position after found pattern to end of string.
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
double ossim_float64
ossim_int64 memoryUnitToInt64() const
This takes a string and will test for numeric followed by a unit type:
ossimString()
default constructor
Definition: ossimString.h:31
ossimString replaceAllThatMatch(const char *regularExpressionPattern, const char *value="") const
ossimString expandEnvironmentVariable() const
If the variable "$(env_var_name)" is found in the string, where "env_var_name" is any system environm...
static ossimString stripLeading(const ossimString &value, char characterToStrip)
std::string::size_type length() const
Definition: ossimString.h:408
std::string::size_type size() const
Definition: ossimString.h:405
bool toBool() const
String to numeric methods.
std::string::iterator begin()
Definition: ossimString.h:420
unsigned long long ossim_uint64
unsigned int ossim_uint32
std::string::iterator erase(std::string::iterator p)
Erases the character at position p.
Definition: ossimString.h:736
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
ossim_float64 toFloat64() const
unsigned long toULong() const
ossim_float32 toFloat32() const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
ossimString urlEncode() const
void compile(const char *)
std::vector< ossimString > explode(const ossimString &delimeter) const
ossim_uint32 start() const
Definition: ossimRegExp.h:209
ossimString replaceStrThatMatch(const char *regularExpressionPattern, const char *value="") const
ossim_uint16 toUInt16() const
ossim_uint32 end() const
Definition: ossimRegExp.h:217
bool is_valid() const
Definition: ossimRegExp.h:232
short ossim_int16
long toLong() const
toLong&#39;s deprecated, please use the toInts...
std::string & replace(std::string::size_type pos, std::string::size_type n, const std::string &s)
Replaces a substring of *this with the string s.
Definition: ossimString.h:870
ossim_uint64 toUInt64() const
ossimString beforePos(std::string::size_type pos) const
long long ossim_int64
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
ossim_int64 toInt64() const
std::string substr(std::string::size_type pos=0, std::string::size_type n=std::string::npos) const
Equivalent to basic_string(*this, pos, n).
Definition: ossimString.h:910
ossimString & gsub(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false)
Substitutes searchKey string with replacementValue and returns a reference to *this.
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
ossimString & upcase()
Upcases this string.
Definition: ossimString.cpp:62
ossimString getOssimId() const
If OSSIM_ID_ENABLED returns the OSSIM_ID which currently is the expanded cvs.
bool find(const char *)
unsigned char ossim_uint8
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
int toInt() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
ossim_int16 toInt16() const
ossimString & downcase()
Downcases this string.
Definition: ossimString.cpp:81
int ossim_int32
const std::string & string() const
Definition: ossimString.h:414
bool isnan(const float &v)
isnan Test for floating point Not A Number (NAN) value.
Definition: ossimCommon.h:91