#include <BaseString.hpp>
Definition at line 27 of file BaseString.hpp.
Public Member Functions | |
| BaseString & | append (const Vector< BaseString > &vector, const BaseString &separator=BaseString(" ")) |
| BaseString & | append (const BaseString &str) |
| Appends another BaseString to the end. | |
| BaseString & | append (char c) |
| Appends a char to the end. | |
| BaseString & | append (const char *s) |
| Appends a char * to the end. | |
| BaseString & | appfmt (const char *ftm,...) |
| Appends a format string a la printf() to the end. | |
| BaseString & | assfmt (const char *ftm,...) |
| Assigns from a format string a la printf(). | |
| BaseString & | assign (const Vector< BaseString > &vector, const BaseString &separator=BaseString(" ")) |
| BaseString & | assign (const BaseString &str, size_t n) |
| Assigns from another BaseString, with maximum length n. | |
| BaseString & | assign (const char *s, size_t n) |
| Assigns from char *s, with maximum length n. | |
| BaseString & | assign (const BaseString &str) |
| Assigns from another BaseString. | |
| BaseString & | assign (const char *s) |
| Assigns from a char *. | |
| BaseString (const BaseString &str) | |
| Constructs a copy of another BaseString. | |
| BaseString (const char *s) | |
| Constructs a copy of a char *. | |
| BaseString () | |
| Constructs an empty string. | |
| const char * | c_str () const |
| Returns a C-style string. | |
| bool | empty () const |
| Checks if the string is empty. | |
| ssize_t | indexOf (char c) |
| ssize_t | lastIndexOf (char c) |
| unsigned | length () const |
| Returns the length of the string. | |
| BaseString & | ndb_tolower () |
| Convert to lowercase. | |
| BaseString & | ndb_toupper () |
| Convert to uppercase. | |
| bool | operator!= (const char *str) const |
| Are two strings not equal? | |
| bool | operator!= (const BaseString &str) const |
| Are two strings not equal? | |
| bool | operator< (const BaseString &str) const |
| Compare two strings. | |
| BaseString & | operator= (const BaseString &str) |
| Assignment operator. | |
| bool | operator== (const char *str) const |
| Are two strings equal? | |
| bool | operator== (const BaseString &str) const |
| Are two strings equal? | |
| int | split (Vector< BaseString > &vector, const BaseString &separator=BaseString(" "), int maxSize=-1) const |
| BaseString | substr (ssize_t start, ssize_t stop=-1) |
| BaseString & | trim (const char *delim=" \t") |
| ~BaseString () | |
| Destructor. | |
Static Public Member Functions | |
| static char ** | argify (const char *argv0, const char *src) |
| static int | snprintf (char *str, size_t size, const char *format,...) |
| static char * | trim (char *src, const char *delim) |
| static int | vsnprintf (char *str, size_t size, const char *format, va_list ap) |
Private Attributes | |
| char * | m_chr |
| unsigned | m_len |
|
|
Constructs an empty string.
Definition at line 22 of file BaseString.cpp. Referenced by split(), and substr().
|
|
|
Constructs a copy of a char *.
Definition at line 29 of file BaseString.cpp. References m_chr, m_len, memcpy, and n. 00030 { 00031 const size_t n = strlen(s); 00032 m_chr = new char[n + 1]; 00033 memcpy(m_chr, s, n + 1); 00034 m_len = n; 00035 }
|
|
|
Constructs a copy of another BaseString.
Definition at line 37 of file BaseString.cpp. References m_chr, m_len, memcpy, and n. 00038 { 00039 const char* const s = str.m_chr; 00040 const size_t n = str.m_len; 00041 char* t = new char[n + 1]; 00042 memcpy(t, s, n + 1); 00043 m_chr = t; 00044 m_len = n; 00045 }
|
|
|
Destructor.
Definition at line 47 of file BaseString.cpp. References m_chr. 00048 { 00049 delete[] m_chr; 00050 }
|
|
||||||||||||
|
Appends a Vector of BaseStrings to the end, each Vector entry separated by separator.
Definition at line 109 of file BaseString.cpp. References append(), and Vector< T >::size(). 00110 { 00111 for(size_t i=0;i<vector.size(); i++) { 00112 append(vector[i]); 00113 if(i<vector.size()-1) 00114 append(separator); 00115 } 00116 return *this; 00117 }
|
|
|
Appends another BaseString to the end.
Definition at line 103 of file BaseString.cpp. References append(), and m_chr.
|
|
|
Appends a char to the end.
Definition at line 98 of file BaseString.cpp. References appfmt(). 00098 { 00099 return appfmt("%c", c); 00100 }
|
|
|
Appends a char * to the end.
Definition at line 85 of file BaseString.cpp. References m_chr, m_len, memcpy, and n. Referenced by MgmtSrvr::alloc_node_id(), append(), appfmt(), assign(), base64_encode(), NDBT_ResultRow::c_str(), check_node_vs_replicas(), Ndbcntr::execCONTINUEB(), fixPortNumber(), NdbTransaction::getNdbIndexOperation(), main(), LocalConfig::readFile(), runTableRename(), runTableRenameNF(), runTableRenameSR(), setup_config(), and MgmtSrvr::start(). 00086 { 00087 const size_t n = strlen(s); 00088 char* t = new char[m_len + n + 1]; 00089 memcpy(t, m_chr, m_len); 00090 memcpy(t + m_len, s, n + 1); 00091 delete[] m_chr; 00092 m_chr = t; 00093 m_len += n; 00094 return *this; 00095 }
|
|
||||||||||||
|
Appends a format string a la printf() to the end.
Definition at line 145 of file BaseString.cpp. References append(), basestring_vsnprintf(), and buf. Referenced by MgmtSrvr::alloc_node_id(), append(), LogHandler::append_impl(), check_node_vs_replicas(), connect_ndb_mgm(), Ndbcntr::execCONTINUEB(), Ndb_mgmclient::execute(), gather_result(), Ndb_mgmd_event_service::log(), main(), ndb_mgm_listen_event_internal(), ndb_mgm_restart2(), ndb_mgm_stop2(), runTestMaxTransaction(), MgmtSrvr::saveConfig(), setup_config(), setup_hosts(), start_process(), and MgmApiSession::stop_session_if_not_connected(). 00146 { 00147 char buf[1]; 00148 va_list ap; 00149 int l; 00150 00151 /* Figure out how long the formatted string will be. A small temporary 00152 * buffer is used, because I don't trust all implementations to work 00153 * when called as vsnprintf(NULL, 0, ...). 00154 */ 00155 va_start(ap, fmt); 00156 l = basestring_vsnprintf(buf, sizeof(buf), fmt, ap) + 1; 00157 va_end(ap); 00158 char *tmp = new char[l]; 00159 va_start(ap, fmt); 00160 basestring_vsnprintf(tmp, l, fmt, ap); 00161 va_end(ap); 00162 append(tmp); 00163 delete[] tmp; 00164 return *this; 00165 }
|
|
||||||||||||
|
Return c-array with strings suitable for execve When whitespace is detected, the characters '"' and '\' are honored, to make it possible to give arguments containing whitespace. The semantics of '"' and '\' match that of most Unix shells. Definition at line 242 of file BaseString.cpp. References iswhite, malloc, NULL, Vector< T >::push_back(), Vector< T >::size(), and strdup(). Referenced by CPCD::Process::do_exec(), and setup_environment(). 00242 { 00243 Vector<char *> vargv; 00244 00245 if(argv0 != NULL) 00246 vargv.push_back(strdup(argv0)); 00247 00248 char *tmp = new char[strlen(src)+1]; 00249 char *dst = tmp; 00250 const char *end = src + strlen(src); 00251 /* Copy characters from src to destination, while compacting them 00252 * so that all whitespace is compacted and replaced by a NUL-byte. 00253 * At the same time, add pointers to strings in the vargv vector. 00254 * When whitespace is detected, the characters '"' and '\' are honored, 00255 * to make it possible to give arguments containing whitespace. 00256 * The semantics of '"' and '\' match that of most Unix shells. 00257 */ 00258 while(src < end && *src) { 00259 /* Skip initial whitespace */ 00260 while(src < end && *src && iswhite(*src)) 00261 src++; 00262 00263 char *begin = dst; 00264 while(src < end && *src) { 00265 /* Handle '"' quotation */ 00266 if(*src == '"') { 00267 src++; 00268 while(src < end && *src && *src != '"') { 00269 if(*src == '\\') 00270 src++; 00271 *dst++ = *src++; 00272 } 00273 src++; 00274 if(src >= end) 00275 goto end; 00276 } 00277 00278 /* Handle '\' */ 00279 if(*src == '\\') 00280 src++; 00281 else if(iswhite(*src)) 00282 break; 00283 00284 /* Actually copy characters */ 00285 *dst++ = *src++; 00286 } 00287 00288 /* Make sure the string is properly terminated */ 00289 *dst++ = '\0'; 00290 src++; 00291 00292 vargv.push_back(strdup(begin)); 00293 } 00294 end: 00295 00296 delete[] tmp; 00297 vargv.push_back(NULL); 00298 00299 /* Convert the C++ Vector into a C-vector of strings, suitable for 00300 * calling execv(). 00301 */ 00302 char **argv = (char **)malloc(sizeof(*argv) * (vargv.size())); 00303 if(argv == NULL) 00304 return NULL; 00305 00306 for(size_t i = 0; i < vargv.size(); i++){ 00307 argv[i] = vargv[i]; 00308 } 00309 00310 return argv; 00311 }
|
|
||||||||||||
|
||||||||||||
|
Assings from a Vector of BaseStrings, each Vector entry separated by separator.
Definition at line 260 of file BaseString.hpp. References append(), and assign().
|
|
||||||||||||
|
Assigns from another BaseString, with maximum length n.
Definition at line 77 of file BaseString.cpp. References assign(), m_chr, and m_len.
|
|
||||||||||||
|
Assigns from char *s, with maximum length n.
Definition at line 65 of file BaseString.cpp. References m_chr, m_len, and memcpy. 00066 { 00067 char* t = new char[n + 1]; 00068 memcpy(t, s, n); 00069 t[n] = 0; 00070 delete[] m_chr; 00071 m_chr = t; 00072 m_len = n; 00073 return *this; 00074 }
|
|
|
Assigns from another BaseString.
Definition at line 254 of file BaseString.hpp. References assign(), and m_chr.
|
|
|
|
|
Checks if the string is empty.
Definition at line 204 of file BaseString.hpp. References m_len. Referenced by NdbDictInterface::createOrAlterTable(), CPCD::Process::do_exec(), NdbTableImpl::getName(), and setup_config(). 00205 { 00206 return m_len == 0; 00207 }
|
|
|
Returns the index of the first occurance of the character c. c character to look for
Definition at line 200 of file BaseString.cpp. References m_chr, NULL, p, and strchr(). 00200 { 00201 char *p; 00202 p = strchr(m_chr, c); 00203 if(p == NULL) 00204 return -1; 00205 return (ssize_t)(p-m_chr); 00206 }
|
|
|
Returns the index of the last occurance of the character c. c character to look for
Definition at line 209 of file BaseString.cpp. References m_chr, NULL, p, and strrchr(). 00209 { 00210 char *p; 00211 p = strrchr(m_chr, c); 00212 if(p == NULL) 00213 return -1; 00214 return (ssize_t)(p-m_chr); 00215 }
|
|
|
Returns the length of the string.
Definition at line 198 of file BaseString.hpp. References m_len. Referenced by MgmtSrvr::alloc_node_id(), base64_decode(), Config::change(), check_node_vs_replicas(), NdbTableImpl::getColumn(), MgmApiSession::getConfig_common(), NdbDictionaryImpl::getIndex(), NdbDictInterface::getTable(), insert_file(), NdbDictInterface::listObjects(), ndb_tolower(), ndb_toupper(), read_test_case(), LocalConfig::readFile(), runTestMaxTransaction(), setup_config(), start_process(), MgmtSrvr::startEventLog(), and substr(). 00199 { 00200 return m_len; 00201 }
|
|
|
Convert to lowercase.
Definition at line 217 of file BaseString.hpp. References length(), and m_chr. 00217 { 00218 for(unsigned i = 0; i < length(); i++) 00219 m_chr[i] = tolower(m_chr[i]); 00220 return *this; 00221 }
|
|
|
Convert to uppercase.
Definition at line 210 of file BaseString.hpp. References length(), and m_chr. 00210 { 00211 for(unsigned i = 0; i < length(); i++) 00212 m_chr[i] = toupper(m_chr[i]); 00213 return *this; 00214 }
|
|
|
Are two strings not equal?
Definition at line 248 of file BaseString.hpp. References m_chr. 00249 { 00250 return strcmp(m_chr, str) != 0; 00251 }
|
|
|
Are two strings not equal?
Definition at line 242 of file BaseString.hpp. References m_chr.
|
|
|
Compare two strings.
Definition at line 224 of file BaseString.hpp. References m_chr.
|
|
|
Assignment operator.
Definition at line 168 of file BaseString.cpp. References assign(). 00169 { 00170 if (this != &str) { 00171 this->assign(str); 00172 } 00173 return *this; 00174 }
|
|
|
Are two strings equal?
Definition at line 236 of file BaseString.hpp. References m_chr. 00237 { 00238 return strcmp(m_chr, str) == 0; 00239 }
|
|
|
Are two strings equal?
Definition at line 230 of file BaseString.hpp. References m_chr.
|
|
||||||||||||||||||||
|
||||||||||||||||
|
Split a string into a vector of strings. Separate the string where any character included in separator exists. Maximally maxSize entries are added to the vector, if more separators exist in the string, the remainder of the string will be appended to the last entry in the vector. The vector will not be cleared, so any existing strings in the vector will remain.
Definition at line 177 of file BaseString.cpp. References BaseString(), c_str(), free, int, len, m_chr, Vector< T >::push_back(), Vector< T >::size(), start, strchr(), and strdup(). Referenced by add_host(), add_hosts(), Logger::addHandler(), CPCD::Process::do_exec(), BackupRestore::endOfTables(), CommandInterpreter::executeEventReporting(), CommandInterpreter::executeLogLevel(), insert(), insert_row(), main(), ndb_mgm_get_status(), LogHandler::parseParams(), read_test_case(), set_ulimit(), setup_config(), and BackupRestore::table(). 00179 { 00180 char *str = strdup(m_chr); 00181 int i, start, len, num = 0; 00182 len = strlen(str); 00183 for(start = i = 0; 00184 (i <= len) && ( (maxSize<0) || ((int)v.size()<=maxSize-1) ); 00185 i++) { 00186 if(strchr(separator.c_str(), str[i]) || i == len) { 00187 if(maxSize < 0 || (int)v.size() < maxSize-1) 00188 str[i] = '\0'; 00189 v.push_back(BaseString(str+start)); 00190 num++; 00191 start = i+1; 00192 } 00193 } 00194 free(str); 00195 00196 return num; 00197 }
|
|
||||||||||||
|
Returns a subset of a string
Definition at line 218 of file BaseString.cpp. References assign(), BaseString(), len, length(), and m_chr. Referenced by start_process(). 00218 { 00219 if(stop < 0) 00220 stop = length(); 00221 ssize_t len = stop-start; 00222 if(len <= 0) 00223 return BaseString(""); 00224 BaseString s; 00225 s.assign(m_chr+start, len); 00226 return s; 00227 }
|
|
||||||||||||
|
Trim string from delim Definition at line 321 of file BaseString.cpp. References len, memmove, pos(), and strchr(). 00321 { 00322 int len = strlen(str) - 1; 00323 for(; len > 0 && strchr(delim, str[len]); len--); 00324 00325 int pos = 0; 00326 for(; pos <= len && strchr(delim, str[pos]); pos++); 00327 00328 if(pos > len){ 00329 str[0] = 0; 00330 return 0; 00331 } else { 00332 memmove(str, &str[pos], len - pos + 1); 00333 str[len-pos+1] = 0; 00334 } 00335 00336 return str; 00337 }
|
|
|
Trim string from delim Definition at line 314 of file BaseString.cpp. Referenced by CommandInterpreter::execute_impl(), insert(), insert_row(), ndb_mgm_get_status(), read_test_case(), LocalConfig::readFile(), and setup_config().
|
|
||||||||||||||||||||
|
Definition at line 340 of file BaseString.cpp. References basestring_vsnprintf(). Referenced by chkerror(), fatal(), fatal_dict(), SimulatedBlock::infoEvent(), Logger::log(), ndberror(), ndbout_c(), InitConfigFileParser::Context::reportError(), InitConfigFileParser::Context::reportWarning(), setError(), vprint_socket(), vprintln_socket(), and SimulatedBlock::warningEvent(). 00341 { 00342 return(basestring_vsnprintf(str, size, format, ap)); 00343 }
|
|
|
Definition at line 187 of file BaseString.hpp. Referenced by append(), assfmt(), assign(), BaseString(), c_str(), indexOf(), lastIndexOf(), ndb_tolower(), ndb_toupper(), operator!=(), operator<(), operator==(), split(), substr(), trim(), and ~BaseString(). |
|
|
Definition at line 188 of file BaseString.hpp. Referenced by append(), assfmt(), assign(), BaseString(), empty(), length(), and trim(). |
1.4.3