Set data contents.
179 if(contents.size()<1)
return;
181 while(contents.find(
" ",index) == index)
183 if(index >= contents.size())
return;
185 size_t end_index=contents.size()-1;
186 while(contents.rfind(
" ",end_index) == end_index)
189 if(end_index <= index || end_index > contents.size())
return;
191 std::string key,
value,tmp;
194 while(index <= end_index) {
196 auto next_marker = this->
search(contents,index);
198 if(next_marker.first ==
kString) {
202 while(next_marker.second < end_index+1) {
204 next_marker = this->
search(contents,next_marker.second+1);
206 if(next_marker.first ==
kString) {
207 next_marker = this->
search(contents,next_marker.second+1);
214 if(next_marker.second > end_index)
break;
215 if(next_marker.first ==
kNone)
break;
225 key = contents.substr(index,(next_marker.second-index));
229 tmp = contents.substr(index,(next_marker.second-index));
233 size_t sep_index = tmp.rfind(
" ");
234 if(sep_index >= tmp.size()) {
235 std::cerr <<
"Invalid format (key:value)" << std::endl;
236 throw std::exception();
238 value = tmp.substr(0,sep_index);
243 key = tmp.substr(sep_index+1,(tmp.size()-sep_index-1));
247 }
else if(next_marker.first ==
kBlockEnd) {
248 std::cerr <<
"Block end logic error!" << std::endl;
249 throw std::exception();
255 std::cerr <<
"Invalid paramter set start!" << std::endl;
256 throw std::exception();
261 index = next_marker.second + 1;
262 while(start_ctr && next_marker.second <= end_index) {
264 next_marker = this->
search(contents,next_marker.second+1);
266 if(next_marker.first ==
kString) {
268 while(next_marker.second < end_index+1) {
270 next_marker = this->
search(contents,next_marker.second+1);
272 auto tmp_next_marker = this->
search(contents,next_marker.second+1);
274 if(next_marker.first ==
kString && tmp_next_marker.second !=
kString) {
276 next_marker = tmp_next_marker;
284 switch(next_marker.first){
297 std::cerr <<
"Invalid block:\n" << contents.substr(index,next_marker.second-index) <<
"\n" << std::endl;
298 throw std::exception();
300 value = contents.substr(index,next_marker.second-index);
309 std::cerr <<
"Unknown error!" << std::endl;
310 throw std::exception();
313 index = next_marker.second+1;
314 last_mark = next_marker.first;
317 if(index <= end_index) {
319 if(!value.empty()) {
std::cerr <<
"Non-empty value @ process-end!" << std::endl;
throw std::exception(); }
320 if(key.empty()) {
std::cerr <<
"Empty key @ process-end!" << std::endl;
throw std::exception(); }
322 tmp = contents.substr(index+1,end_index-index);
325 if(tmp.empty()) {
std::cerr <<
"Empty value @ end!" << std::endl;
throw std::exception(); }
333 if(!key.empty() || !value.empty()) {
334 std::cerr <<
"Unpaired key:value!" << std::endl;
335 throw std::exception();
BEGIN_PROLOG could also be cerr
void no_space(std::string &txt)
void add_pset(const PSet &p)
Insert method for a PSet rep.
void add_value(std::string key, std::string value)
Insert method for a simple param.
void rstrip(std::string &str, const std::string &key)
void trim_space(std::string &txt)
std::pair< PSet::KeyChar_t, size_t > search(const std::string &txt, const size_t start) const
void strip(std::string &str, const std::string &key)