3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 std::string trim(const std::string &str);
31 void start(std::string niinq){
38 void to(unsigned int i){
44 std::string next(std::string plop){
45 //std::cout<<"tek=\""<<tek<<"\" plop=\""<<plop<<"\""<<std::endl;
50 //std::cout<<"\tp<tek.size()"<<std::endl;
51 if ((n = tek.find(plop, p)) == std::string::npos || plop == "")
53 //std::cout<<"\t\tn == string::npos || plop == \"\""<<std::endl;
58 //std::cout<<"\t\tn != string::npos"<<std::endl;
60 palautus = tek.substr(p, n-p);
61 p = n + plop.length();
64 //std::cout<<"\tp>=tek.size()"<<std::endl;
65 //std::cout<<"palautus=\""<<palautus<<"\""<<std::endl;
69 // Returns substr of tek up to the next occurence of plop that isn't escaped with '\'
70 std::string next_esc(std::string plop) {
78 n = tek.find(plop, p);
79 if (n == std::string::npos || plop == "")
81 p = n + plop.length();
82 } while (n > 0 && tek[n - 1] == '\\');
84 return tek.substr(realp, n - realp);
87 void skip_over(std::string chars){
88 while(p < tek.size()){
90 for(unsigned int i=0; i<chars.size(); i++){
91 if(chars[i] == tek[p]){
101 if(p>=tek.size()) return true;
104 Strfnd(std::string s){
113 void start(std::wstring niinq){
117 unsigned int where(){
120 void to(unsigned int i){
126 std::wstring next(std::wstring plop){
127 //std::cout<<"tek=\""<<tek<<"\" plop=\""<<plop<<"\""<<std::endl;
129 std::wstring palautus;
132 //std::cout<<"\tp<tek.size()"<<std::endl;
133 if ((n = tek.find(plop, p)) == std::wstring::npos || plop == L"")
135 //std::cout<<"\t\tn == string::npos || plop == \"\""<<std::endl;
140 //std::cout<<"\t\tn != string::npos"<<std::endl;
142 palautus = tek.substr(p, n-p);
143 p = n + plop.length();
146 //std::cout<<"\tp>=tek.size()"<<std::endl;
147 //std::cout<<"palautus=\""<<palautus<<"\""<<std::endl;
151 std::wstring next_esc(std::wstring plop) {
159 n = tek.find(plop, p);
160 if (n == std::wstring::npos || plop == L"")
162 p = n + plop.length();
163 } while (n > 0 && tek[n - 1] == '\\');
165 return tek.substr(realp, n - realp);
169 if(p>=tek.size()) return true;
172 WStrfnd(std::wstring s){
177 inline std::string trim(const std::string &s)
184 str.substr(0, 1)==" " ||
185 str.substr(0, 1)=="\t" ||
186 str.substr(0, 1)=="\r" ||
187 str.substr(0, 1)=="\n" ||
188 str.substr(str.length()-1, 1)==" " ||
189 str.substr(str.length()-1, 1)=="\t" ||
190 str.substr(str.length()-1, 1)=="\r" ||
191 str.substr(str.length()-1, 1)=="\n"
195 if (str.substr(0, 1)==" ")
196 str = str.substr(1,str.length()-1);
197 else if (str.substr(0, 1)=="\t")
198 str = str.substr(1,str.length()-1);
199 else if (str.substr(0, 1)=="\r")
200 str = str.substr(1,str.length()-1);
201 else if (str.substr(0, 1)=="\n")
202 str = str.substr(1,str.length()-1);
203 else if (str.substr(str.length()-1, 1)==" ")
204 str = str.substr(0,str.length()-1);
205 else if (str.substr(str.length()-1, 1)=="\t")
206 str = str.substr(0,str.length()-1);
207 else if (str.substr(str.length()-1, 1)=="\r")
208 str = str.substr(0,str.length()-1);
209 else if (str.substr(str.length()-1, 1)=="\n")
210 str = str.substr(0,str.length()-1);