#include <ChString.h>
Public Member Functions | |
| ChString (const XMLCh *ch) | |
Static Public Member Functions | |
| int | Split (const char *text, const char *delim, std::vector< std::string > &fields) |
| String handling utilities. | |
| bool | IsTrue (const std::string &s) |
| bool | IsFalse (const std::string &s) |
| void | Trim (std::string &s) |
Definition at line 17 of file ChString.h.
|
|
Definition at line 19 of file ChString.h.
00019 {
00020 char* c = XMLString::transcode(ch);
00021 (*static_cast<std::string*>(this)) = c;
00022 XMLString::release(&c);
00023 }
|
|
|
Definition at line 104 of file ChString.cxx. Referenced by jobc::nodeBuilder::Build(), and xmli::boolBuilder::Build().
00105 {
00106 //======================================================================
00107 // Is the string s a representation of "false"
00108 //======================================================================
00109 if (s == "0") return true;
00110 if (s == "f") return true;
00111 if (s == "false") return true;
00112 if (s == "F") return true;
00113 if (s == "False") return true;
00114 if (s == "FALSE") return true;
00115 if (s == "off") return true;
00116 if (s == "Off") return true;
00117 if (s == "OFF") return true;
00118 if (s == "n") return true;
00119 if (s == "N") return true;
00120 if (s == "no") return true;
00121 if (s == "No") return true;
00122 if (s == "NO") return true;
00123 return false;
00124 }
|
|
|
Definition at line 80 of file ChString.cxx. Referenced by jobc::nodeBuilder::Build(), cfg::configBuilder::Build(), and xmli::boolBuilder::Build().
00081 {
00082 //======================================================================
00083 // Is the string s a representation of "true"
00084 //======================================================================
00085 if (s == "1") return true;
00086 if (s == "t") return true;
00087 if (s == "true") return true;
00088 if (s == "T") return true;
00089 if (s == "True") return true;
00090 if (s == "TRUE") return true;
00091 if (s == "on") return true;
00092 if (s == "On") return true;
00093 if (s == "ON") return true;
00094 if (s == "y") return true;
00095 if (s == "Y") return true;
00096 if (s == "yes") return true;
00097 if (s == "Yes") return true;
00098 if (s == "YES") return true;
00099 return false;
00100 }
|
|
||||||||||||||||
|
String handling utilities.
Definition at line 16 of file ChString.cxx. Referenced by xmli::xmlfileBuilder::Build(), xmli::ushortBuilder::Build(), xmli::uintBuilder::Build(), xmli::stringBuilder::Build(), xmli::shortBuilder::Build(), jobc::linkBuilder::Build(), xmli::intBuilder::Build(), xmli::floatBuilder::Build(), xmli::doubleBuilder::Build(), xmli::boolBuilder::Build(), and xmli::MakePath().
00019 {
00020 //======================================================================
00021 // Split the text line "line" into sub-strings deliminated by the
00022 // character tokens listed in the string "tok". Returns the number
00023 // of fields added to the vector "fields"
00024 //======================================================================
00025 bool inDQuotedStr = false;
00026 bool inSQuotedStr = false;
00027 bool specialChar = false;
00028 const char* c = line;
00029 int nfields = 0;
00030 std::string f;
00031
00032 for (; *c!='\0'; ++c) {
00033 int istoken = 0;
00034 const char* t;
00035
00036 // If last character was '\' interpret this character literally
00037 if (specialChar) { f+= *c; specialChar = false; continue; }
00038
00039 // If this character is a '\' raise the special character flag
00040 if (*c == '\\') { specialChar = true; continue; }
00041
00042 // Determine if we're entering or leaving a quoted string
00043 if (*c == '\"') { inDQuotedStr = !inDQuotedStr; continue; }
00044 if (*c == '\'') { inSQuotedStr = !inSQuotedStr; continue; }
00045
00046 // In quoted string just copy everything until the close quotes
00047 if (inDQuotedStr) { f+= *c; continue; }
00048 if (inSQuotedStr) { f+= *c; continue; }
00049
00050 // Determine if this character is one of the deliminators
00051 for (t=tok; *t!='\0'; ++t) if (*t==*c) ++istoken;
00052
00053 // Handle non-token charaters
00054 if (istoken == 0) { f+= *c; continue; }
00055
00056 // Handle token charaters
00057 if (istoken>0) {
00058 if (f!="") { // Don't allow empty strings
00059 fields.push_back(f);
00060 ++nfields;
00061 f = "";
00062 }
00063 }
00064 }
00065 // Take care of the last one
00066 if (f!="") {
00067 fields.push_back(f);
00068 ++nfields;
00069 f = "";
00070 }
00071 if (inSQuotedStr || inDQuotedStr) {
00072 std::cerr << "Unterminated string: '"<<line<<"'"<<std::endl;
00073 abort();
00074 }
00075 return nfields;
00076 }
|
|
|
Definition at line 128 of file ChString.cxx. Referenced by cfg::paramBuilder::Build().
00129 {
00130 //======================================================================
00131 // Remove extra white space from the string s
00132 //======================================================================
00133 const char* s1 = s.c_str();
00134 const char* s2 = s1 + s.length() - 1;
00135 while ( iswspace(*s1) ) ++s1;
00136 while ( iswspace(*s2) ) --s2;
00137 const char* si;
00138 std::string stmp;
00139 for (si=s1; si<=s2; ++si) {
00140 if (iswspace(*si) && !iswspace(*(si-1))) stmp += " ";
00141 else stmp += (*si);
00142 }
00143 s = stmp;
00144 }
|
1.3.5