Debian Codegraph @

src/GStringUtil.cc

raw symbols SCIP
1 /*
2 This file is part of the GVars3 Library.
3
4 Copyright (C) 2005 The Authors
5
6 This library is free software, see LICENSE file for details
7 */
8
9 #include "gvars3/GStringUtil.h"
10
11 using namespace std;
12
13 namespace GVars3
14 {
15
16 string UncommentString(string s)
17 {
18 //int n = s.find("//");
19 //return s.substr(0,n);
20
21 int q=0;
22
23 for(string::size_type n=0; n < s.size(); n++)
24 {
25 if(s[n] == '"')
26 q = !q;
27
28 if(s[n] == '/' && !q)
29 {
30 if(n < s.size() -1 && s[n+1] == '/')
31 return s.substr(0, n);
32 }
33 }
34
35 return s;
36 };
37
38 vector<string> ChopAndUnquoteString(string s)
39 {
40 vector<string> v;
41 string::size_type nPos=0;
42 string::size_type nLength = s.length();
43 while(1)
44 {
45 string sTarget;
46 char cDelim;
47 // Get rid of leading whitespace:
48 while((nPos<nLength)&&(s[nPos]==' '))
49 nPos++;
50 if(nPos==nLength)
51 return v;
52
53 // First non-whitespace char...
54 if(s[nPos]!='\"')
55 cDelim=' ';
56 else
57 {
58 cDelim = '\"';
59 nPos++;
60 }
61 for (; nPos < nLength; ++nPos) {
62 char c = s[nPos];
63 if (c == cDelim)
64 break;
65 if (cDelim == '"' && nPos+1<nLength && c == '\\') {
66 char escaped = s[++nPos];
67 switch (escaped) {
68 case 'n': c = '\n'; break;
69 case 'r': c = '\r'; break;
70 case 't': c = '\t'; break;
71 default: c = escaped; break;
72 }
73 }
74 sTarget+=c;
75 }
76 v.push_back(sTarget);
77
78 if(cDelim=='\"')
79 nPos++;
80 }
81 };
82
83 }