Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
navgetxmldata.cpp
Go to the documentation of this file.
1 #include "navgetxmldata.h"
2 
3 using std::string;
4 
5 string retrievedata( string data, string type )
6 {
7  int length = data.size();
8  if (length == 0)
9  return "";
10  if (type.size() == 0)
11  return "";
12  int testlength = type.size();
13  char testchar = 'p';
14  string teststring = "";
15 
16  int counter = 0;
17  while (counter < length) {
18  if (data[counter] == '=') {
19  //find an =
20  int tempcounter = counter;
21  teststring = "";
22  while (tempcounter > 0) {
23  //count backwards to find its start
24  tempcounter = tempcounter-1;
25  testchar = data[tempcounter];
26  if ( (testchar == '"') || (tempcounter == 0) || (testchar == ' ') ) {
27  //found its start
28  if (tempcounter == 0)
29  teststring = testchar+teststring;
30  //if(testchar == ' ')
31  //teststring = ' ' + teststring;
32 
33  //kill spaces at front and back
34  //***********************************
35  int startspaces = 0;
36  int endspaces = teststring.size()-1;
37  string possibletype = "";
38  while (teststring[startspaces] == ' ')
39  startspaces += 1;
40  while (teststring[endspaces] == ' ')
41  endspaces -= 1;
42  for (int j = startspaces; j <= endspaces; j++)
43  possibletype = possibletype+teststring[j];
44  //***********************************
45  //if match, return the data afterwards
46  //***********************************
47  if (possibletype == type) {
48  //cout << possibletype;
49  size_t returncounter = counter;
50  string returnstring = "";
51  returncounter += 1; //pass the =
52  while (data[returncounter] == ' ')
53  returncounter += 1;
54  returncounter += 1; //pass the "
55  while (data[returncounter] == ' ') //pass starting spaces in answer
56  returncounter += 1;
57  while ( returncounter < (data.size()-1) ) {
58  if ( (data[returncounter] == '"') || (data[returncounter] == ' ') ) //read upto the second comment
59  break;
60  returnstring = returnstring+data[returncounter];
61  returncounter += 1;
62  }
63  return returnstring;
64  }
65  //***********************************
66  else {
67  break;
68  }
69  break;
70  }
71  teststring = testchar+teststring;
72  }
73  }
74  counter += 1;
75  }
76  return "";
77 }
78