OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimXmlString.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Ken Melero (kmelero@remotesensing.org)
6 // Description: This class provides manipulation of filenames.
7 //
8 //*************************************************************************
9 // $Id: ossimXmlString.cpp 22326 2013-07-25 17:13:55Z gpotts $
11 
13 {
14  for(ossimString::const_iterator it = value.begin();
15  it != value.end();++it)
16  {
17  switch(*it)
18  {
19  case '&':
20  case '<':
21  case '>':
22  case '"':
23  case '\'':
24  {
25  return true;
26  }
27  default:
28  {
29  break;
30  }
31  }
32 
33  }
34  return false;
35 }
36 
38 {
39  ossimString result = s;
40 
41  std::string::size_type pos = 0;
42 
43  pos = result.find("&");
44  // do ampersand first
45  //
46  while(pos != std::string::npos)
47  {
48  ossimString s1(result.begin() + pos,
49  result.begin()+pos+5);
50  ossimString s2(result.begin() + pos,
51  result.begin()+pos+4);
52  ossimString s3(result.begin() + pos,
53  result.begin()+pos+3);
54 
55  if((s2 != "&amp")&&
56  (s1 != "&quot")&&
57  (s3 != "&gt")&&
58  (s3 != "&lt")&&
59  (s1 != "&apos"))
60  {
61  result.replace(pos, 1, "&amp");
62  }
63 
64  pos = result.find("&", pos+4);
65  }
66 
67  result = result.substitute("\"",
68  "&quot",
69  true);
70  result = result.substitute("<",
71  "&lt",
72  true);
73  result = result.substitute(">",
74  "&gt",
75  true);
76  result = result.substitute("'",
77  "&apos",
78  true);
79 
80  *((ossimString*)this) = result;
81 
82  return *this;
83 }
84 
86 {
88  {
89  return wrapCData(input);
90  }
91 
92  return input;
93 }
95 {
96  return "<![CDATA[" + input + "]]>";
97 }
98 
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
std::string::const_iterator const_iterator
Definition: ossimString.h:26
static bool containsSpecialXmlCharacters(const ossimString &value)
const ossimXmlString & assign(const ossimString &s)
std::string::iterator end()
Definition: ossimString.h:423
std::string::iterator begin()
Definition: ossimString.h:420
static ossimString wrapCDataIfNeeded(const ossimString &input)
static ossimString wrapCData(const ossimString &input)
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
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