00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016 #include "UgliGeometry/UgliDbiTableDescr.h"
00017 #include "Util/UtilString.h"
00018
00019
00020
00021
00022
00023
00024 #include "MessageService/MsgService.h"
00025 CVSID("$Id: UgliDbiTableDescr.cxx,v 1.4 2005/04/29 04:49:06 minoscvs Exp $");
00026
00027
00028
00029
00030
00031
00032
00033 vector<pair<string,string> >
00034 UgliDbiTableDescr::ParseTableDescr(string tabledescr)
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 string trimmed = TrimToParentheses(tabledescr);
00055
00056 trimmed = trimmed.substr(1,trimmed.size()-2);
00057
00058 vector<pair<string,string> > components;
00059
00060 string::size_type start = 0;
00061 string::size_type end = trimmed.size();
00062 string::size_type comma;
00063 while (start < end) {
00064 comma = trimmed.find_first_of(",",start);
00065
00066
00067
00068 if ( string::npos == comma ) comma = end;
00069
00070 string onepair = trimmed.substr(start,comma-start);
00071
00072
00073 onepair = TrimWhiteSpace(onepair,true,true);
00074
00075
00076 string::size_type first_blank = onepair.find_first_of(" ");
00077 string::size_type last_blank = onepair.find_last_of(" ");
00078
00079
00080 string colName = onepair.substr(0,first_blank);
00081 string colType = onepair.substr(last_blank+1,onepair.size()-last_blank);
00082
00083
00084
00085 pair<string,string> colPair(colName,colType);
00086 components.push_back(colPair);
00087
00088
00089 start = comma + 1;
00090 }
00091
00092 #ifdef DUMPRESUL
00093 MSG("Ugli",Msg::kInfo)
00094 << "UgliDbiTableDescr::ParseTableDescr starts with '"
00095 << tabledescr << "'" << endl;
00096 int n = components.size();
00097 MSG("Ugli",Msg::kInfo)
00098 << " result was " << n << " components" << endl;
00099 for (int i=0; i<n; i++) {
00100 pair<string,string> colPair = components[i];
00101 MSG("Ugli",Msg::kInfo)
00102 << " i=" << i << " '"
00103 << colPair.first << "' : '"
00104 << colPair.second << "'" << endl;
00105 }
00106 #endif
00107
00108 return components;
00109 }
00110
00111
00112 string UgliDbiTableDescr::TrimWhiteSpace(string input,
00113 bool fromFront, bool fromBack)
00114 {
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 if (!fromFront && !fromBack) return input;
00134
00135 string::size_type start = 0;
00136 string::size_type end = input.size()-1;
00137
00138 string delim = " \t\n\r\b\f\v";
00139
00140 if (fromFront) start = input.find_first_not_of(delim);
00141 if (fromBack) end = input.find_last_not_of(delim);
00142
00143 return input.substr(start,end+1-start);
00144
00145 }
00146
00147
00148
00149 string UgliDbiTableDescr::TrimToParentheses(string full_create,
00150 bool remove_paren)
00151 {
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 string::size_type start = full_create.find("(");
00171 string::size_type end = full_create.rfind(")");
00172
00173 if (start == string::npos || end == string::npos) {
00174 MSG("Ugli",Msg::kInfo)
00175 << "UgliDbiTableDescr found unmatched parentheses in:" << endl
00176 << full_create << endl;
00177 return "";
00178 }
00179
00180 if ( ! remove_paren ) return full_create.substr(start,end+1-start);
00181 else return full_create.substr(start+1,end+1-start-2);
00182 }
00183
00184
00185
00186 string UgliDbiTableDescr::TextTableDescrLine(string tabledescr)
00187 {
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 tabledescr = UgliDbiTableDescr::TrimToParentheses(tabledescr,true);
00209
00210 size_t pos;
00211
00212
00213
00214
00215
00216
00217 if ( true ) {
00218 pos = tabledescr.rfind(" ");
00219 while ( pos != string::npos && pos > 0 ) {
00220 tabledescr.erase(pos,1);
00221 pos = tabledescr.rfind(" ");
00222 }
00223 }
00224 tabledescr = TrimWhiteSpace(tabledescr);
00225 tabledescr = UtilString::ToUpper(tabledescr);
00226
00227 return tabledescr;
00228 }
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262