Go to the documentation of this file.00001 #include "mbl_parse_keyword_list.h"
00002
00003
00004
00005
00006
00007 #include <mbl/mbl_exception.h>
00008 #include <mbl/mbl_parse_block.h>
00009 #include <vcl_sstream.h>
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 void mbl_parse_keyword_list(vcl_istream& is, const vcl_string& keyword,
00024 vcl_vector<vcl_string>& items,
00025 bool discard_comments )
00026 {
00027 vcl_string s = mbl_parse_block(is);
00028 vcl_istringstream ss(s);
00029 char c;
00030 ss>>c;
00031 if (c!='{')
00032 {
00033 throw mbl_exception_parse_error("Expected '{' in mbl_parse_keyword_list");
00034 }
00035
00036 items.resize(0);
00037 vcl_string label;
00038 while (!ss.eof())
00039 {
00040 ss >> label;
00041
00042 if (label == "}")
00043 continue;
00044
00045 else if ( discard_comments && (label.substr(0,2) == "//") )
00046 {
00047
00048 vcl_string comment_string;
00049 vcl_getline(ss, comment_string);
00050 continue;
00051 }
00052
00053 else if (label!=keyword)
00054 {
00055 vcl_string error_msg = "Expected keyword: '";
00056 error_msg+=keyword;
00057 error_msg+="' Got '";
00058 error_msg+=label;
00059 error_msg+="'";
00060 throw mbl_exception_parse_error(error_msg);
00061 }
00062
00063 items.push_back(mbl_parse_block(ss));
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 void mbl_parse_keyword_list2(vcl_istream& is, const vcl_string& keyword,
00077 vcl_vector<vcl_string>& items,
00078 bool discard_comments )
00079 {
00080 vcl_string s = mbl_parse_block(is);
00081 vcl_istringstream ss(s);
00082 char c;
00083 ss>>c;
00084 if (c!='{')
00085 {
00086 throw mbl_exception_parse_error("Expected '{' in mbl_parse_keyword_list");
00087 }
00088
00089 items.resize(0);
00090 vcl_string label,string1,string2;
00091 while (!ss.eof())
00092 {
00093 ss >> label;
00094
00095 if (label == "}")
00096 continue;
00097
00098 else if ( discard_comments && (label.substr(0,2) == "//") )
00099 {
00100
00101 vcl_string comment_string;
00102 vcl_getline(ss, comment_string);
00103 continue;
00104 }
00105
00106 if (label!=keyword)
00107 {
00108 vcl_string error_msg = "Expected keyword: '";
00109 error_msg+=keyword;
00110 error_msg+="' Got '";
00111 error_msg+=label;
00112 error_msg+="'";
00113 throw mbl_exception_parse_error(error_msg);
00114 }
00115
00116 ss>>string1;
00117 string2=string1 + " " + mbl_parse_block(ss);
00118
00119 items.push_back(string2);
00120 }
00121 }
00122
00123