#include <UgliDbiTableDescr.h>
Static Public Member Functions | |
| vector< pair< string, string > > | ParseTableDescr (string tabledescr) |
| string | TrimWhiteSpace (string input, bool fromFront=true, bool fromBack=true) |
| string | TrimToParentheses (string full_create, bool remove_paren=false) |
| string | TextTableDescrLine (string tabledescr) |
|
|
Definition at line 34 of file UgliDbiTableDescr.cxx. References MSG, TrimToParentheses(), and TrimWhiteSpace(). Referenced by UgliDbiStripStruct::FormatToOStream(), UgliDbiStrip::FormatToOStream(), UgliDbiSteelPln::FormatToOStream(), UgliDbiScintPlnStruct::FormatToOStream(), UgliDbiScintPln::FormatToOStream(), UgliDbiScintMdlStruct::FormatToOStream(), UgliDbiScintMdl::FormatToOStream(), UgliDbiGeometry::FormatToOStream(), UgliDbiStripStruct::Store(), UgliDbiStrip::Store(), UgliDbiSteelPln::Store(), UgliDbiScintPlnStruct::Store(), UgliDbiScintPln::Store(), UgliDbiScintMdlStruct::Store(), UgliDbiScintMdl::Store(), and UgliDbiGeometry::Store(). 00035 {
00036 //
00037 // Purpose: Break down tabledescr into a vector of column names and types
00038 //
00039 // Arguments: "( ColName0 ColType0, ColName1 ColType1, ... )"
00040 //
00041 // Return: vector of pair<"ColNameN","ColTypeN">
00042 //
00043 // Contact: R. Hatcher
00044 //
00045 // Specification:-
00046 // =============
00047 //
00048 // Program Notes:-
00049 // =============
00050
00051 // None.
00052
00053 // trim the input string
00054 string trimmed = TrimToParentheses(tabledescr);
00055 // remove lead and trailing parentheses
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 // cout << " start " << start << " comma " << comma << endl;
00066
00067 // handle case of no delimiters before end-of-string;
00068 if ( string::npos == comma ) comma = end;
00069
00070 string onepair = trimmed.substr(start,comma-start);
00071
00072 // trim lead/trail blanks
00073 onepair = TrimWhiteSpace(onepair,true,true);
00074 // cout << " onepair '" << onepair << "'" << endl;
00075
00076 string::size_type first_blank = onepair.find_first_of(" ");
00077 string::size_type last_blank = onepair.find_last_of(" ");
00078 // cout << " first " << first_blank << " last " << last_blank << endl;
00079
00080 string colName = onepair.substr(0,first_blank);
00081 string colType = onepair.substr(last_blank+1,onepair.size()-last_blank);
00082 // cout << " colName '" << colName
00083 // << "' colType '" << colType << "'" << endl;
00084
00085 pair<string,string> colPair(colName,colType);
00086 components.push_back(colPair);
00087
00088 // move past comma
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 }
|
|
|
Definition at line 186 of file UgliDbiTableDescr.cxx. References UtilString::ToUpper(), TrimToParentheses(), and TrimWhiteSpace(). Referenced by UgliDbiStripStruct::FormatToOStream(), UgliDbiStrip::FormatToOStream(), UgliDbiSteelPln::FormatToOStream(), UgliDbiScintPlnStruct::FormatToOStream(), UgliDbiScintPln::FormatToOStream(), UgliDbiScintMdlStruct::FormatToOStream(), UgliDbiScintMdl::FormatToOStream(), and UgliDbiGeometry::FormatToOStream(). 00187 {
00188 //
00189 // Purpose: Reformat string for use in ASCII table usage including
00190 // no SQL command (ie. just fields and types),
00191 // comma separation, minimal spaces, trimming,
00192 //
00193 // Arguments: "create table if not exists UgliDbiGeometry ( ... ) ;"
00194 //
00195 // Return: "..."
00196 //
00197 // Contact: R. Hatcher
00198 //
00199 // Specification:-
00200 // =============
00201 //
00202
00203 // Program Notes:-
00204 // =============
00205
00206 // None.
00207
00208 tabledescr = UgliDbiTableDescr::TrimToParentheses(tabledescr,true);
00209
00210 size_t pos;
00211 //pos = tabledescr.find("(");
00212 //tabledescr.erase(pos,1);
00213 //pos = tabledescr.find(")");
00214 //tabledescr.erase(pos,1);
00215
00216 // remove double spaces
00217 if ( true ) {
00218 pos = tabledescr.rfind(" ");
00219 while ( pos != string::npos && pos > 0 ) {
00220 tabledescr.erase(pos,1); // erase one-of-two spaces
00221 pos = tabledescr.rfind(" ");
00222 }
00223 }
00224 tabledescr = TrimWhiteSpace(tabledescr);
00225 tabledescr = UtilString::ToUpper(tabledescr);
00226
00227 return tabledescr;
00228 }
|
|
||||||||||||
|
Definition at line 149 of file UgliDbiTableDescr.cxx. References MSG. Referenced by ParseTableDescr(), and TextTableDescrLine(). 00151 {
00152 //
00153 // Purpose: Trim string down to just parenthesized comma separated list
00154 //
00155 // Arguments: "create table if not exists UgliDbiGeometry ( ... ) ;"
00156 //
00157 // Return: "( ... )"
00158 //
00159 // Contact: R. Hatcher
00160 //
00161 // Specification:-
00162 // =============
00163 //
00164
00165 // Program Notes:-
00166 // =============
00167
00168 // None.
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 }
|
|
||||||||||||||||
|
Definition at line 112 of file UgliDbiTableDescr.cxx. Referenced by ParseTableDescr(), and TextTableDescrLine(). 00114 {
00115 //
00116 // Purpose: Trim away leading/trailing blanks, tabs, newlines
00117 //
00118 // Arguments: " xyzyz "
00119 //
00120 // Return: "xyzzy"
00121 //
00122 // Contact: R. Hatcher
00123 //
00124 // Specification:-
00125 // =============
00126 //
00127
00128 // Program Notes:-
00129 // =============
00130
00131 // None.
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 }
|
1.3.9.1