#include <cmt_string.h>
Public Types | |
enum | pos_type { npos = -1 } |
Public Methods | |
cmt_string () | |
cmt_string (int n) | |
cmt_string (char c) | |
cmt_string (const char* text) | |
cmt_string (const cmt_string& other) | |
~cmt_string () | |
cmt_string& | operator= (char c) |
cmt_string& | operator= (const char* text) |
cmt_string& | operator= (const cmt_string& other) |
bool | read (const cmt_string& file_name) |
bool | write (const cmt_string& file_name) const |
void | write (FILE* f) const |
void | write (ostream& output) |
operator const char * () const | |
const char* | c_str () const |
void | operator+= (char c) |
void | operator+= (const char* text) |
void | operator+= (const cmt_string& other) |
cmt_string | operator+ (char c) const |
cmt_string | operator+ (const char* text) const |
cmt_string | operator+ (const cmt_string& other) const |
char | operator[] (int index) const |
char& | operator[] (int index) |
int | size () const |
int | size () |
void | resize (int n) |
int | find (char c) const |
int | find (const char* text) const |
int | find (const cmt_string& other) const |
int | find (int pos, char c) const |
int | find (int pos, const char* text) const |
int | find (int pos, const cmt_string& other) const |
int | find_last_of (char c) const |
int | find_last_of (const char* text) const |
int | find_last_of (const cmt_string& other) const |
void | erase (int pos) |
void | erase (int pos, int length) |
void | replace (const char* pattern, const char* replacement) |
void | replace (const cmt_string& pattern, const cmt_string& replacement) |
void | replace_all (const char* pattern, const char* replacement) |
void | replace_all (const cmt_string& pattern, const cmt_string& replacement) |
void | trim () |
cmt_string | substr (int pos) const |
cmt_string | substr (int pos, int length) const |
void | substr (int pos, cmt_string& dest) const |
void | substr (int pos, int length, cmt_string& dest) const |
bool | operator< (const char* text) const |
bool | operator< (const cmt_string& other) const |
bool | operator== (const char* text) const |
bool | operator== (const cmt_string& other) const |
bool | compare_no_case (const char* text) const |
bool | compare_no_case (const cmt_string& other) const |
bool | operator!= (const char* text) const |
bool | operator!= (const cmt_string& other) const |
bool | operator> (const char* text) const |
bool | operator> (const cmt_string& other) const |
Private Methods | |
void | extend (int n) |
void | allocate (int n) |
Private Attributes | |
char* | _data |
int | _allocated |
int | _size |
|
Definition at line 10 of file cmt_string.h. 00011 { 00012 npos = -1 00013 } |
|
Definition at line 7 of file cmt_string.cxx. 00008 { 00009 _data = 0; 00010 _allocated = 0; 00011 _size = 0; 00012 } |
|
Definition at line 14 of file cmt_string.cxx. 00015 { 00016 _data = 0; 00017 _allocated = 0; 00018 _size = 0; 00019 allocate (n + 1); 00020 } |
|
Definition at line 22 of file cmt_string.cxx. 00023 { 00024 _data = 0; 00025 _allocated = 0; 00026 _size = 0; 00027 00028 allocate (2); 00029 00030 _data[0] = c; 00031 _data[1] = 0; 00032 _size = 1; 00033 } |
|
Definition at line 35 of file cmt_string.cxx. 00036 { 00037 _data = 0; 00038 _allocated = 0; 00039 _size = 0; 00040 00041 if (text != 0) 00042 { 00043 _size = strlen (text); 00044 allocate (_size + 1); 00045 strcpy (_data, text); 00046 } 00047 } |
|
Definition at line 49 of file cmt_string.cxx. 00050 { 00051 const char* text = other._data; 00052 00053 _data = 0; 00054 _allocated = 0; 00055 _size = 0; 00056 00057 if (text != 0) 00058 { 00059 _size = strlen (text); 00060 allocate (_size + 1); 00061 strcpy (_data, text); 00062 } 00063 } |
|
Definition at line 65 of file cmt_string.cxx. 00066 { 00067 if (_data != 0) 00068 { 00069 #ifdef CMT_USE_NEW_DELETE 00070 delete[] _data; 00071 #else 00072 free (_data); 00073 #endif 00074 } 00075 _data = 0; 00076 _allocated = 0; 00077 _size = 0; 00078 } |
|
Definition at line 656 of file cmt_string.cxx. Referenced by cmt_string(), extend(), operator=(), read(), and resize(). 00657 { 00658 if ((n + 1) > _allocated) 00659 { 00660 static const int quantum = 128; 00661 int frames = ((n + 1)/quantum) + 1; 00662 _allocated = frames * quantum; 00663 00664 #ifdef CMT_USE_NEW_DELETE 00665 char* new_data = new char [_allocated + 1]; 00666 #else 00667 char* new_data = (char*) malloc (_allocated + 1); 00668 #endif 00669 00670 00671 if (_data != 0) 00672 { 00673 strcpy (new_data, _data); 00674 00675 #ifdef CMT_USE_NEW_DELETE 00676 delete[] _data; 00677 #else 00678 free (_data); 00679 #endif 00680 00681 _data = new_data; 00682 } 00683 else 00684 { 00685 new_data[0] = 0; 00686 } 00687 00688 _data = new_data; 00689 } 00690 } |
|
|
|
|
|
|
Definition at line 345 of file cmt_string.cxx. 00346 { 00347 if ((_data == 0) || 00348 (pos < 0) || 00349 (pos >= _size)) 00350 { 00351 return; 00352 } 00353 else 00354 { 00355 if ((pos + length) >= _size) 00356 { 00357 _data[pos] = 0; 00358 _size = pos; 00359 } 00360 else 00361 { 00362 strcpy (&_data[pos], &_data[pos + length]); 00363 _size -= length; 00364 } 00365 } 00366 } |
|
Definition at line 330 of file cmt_string.cxx. Referenced by Language::action(), Script::add(), DepsBuilder::add(), add_cmt_paths(), add_line_to_text(), CmtSystem::basename(), Generator::build_readme(), Generator::check(), Generator::commit(), CmtSystem::compress_path(), Cmt::configure_current_dir(), CmtSystem::dirname(), Cmt::do_broadcast(), Pattern::expand(), CmtModel::expand(), Packager::filter(), DependencyFilter::filter(), CvsImplementation::filter_dir(), CmtSystem::name(), Parser::parse(), Cmt::parse_arguments(), Parser::parse_line(), Cmt::parse_requirements_line(), Cmt::parse_requirements_text(), PackageCollector::run(), CmtSystem::scan_dir(), constituents_action_iterator::set(), Cmt::set_standard_macros(), substr(), trim(), and Cmt::vector_to_string(). 00331 { 00332 if ((_data == 0) || 00333 (pos < 0) || 00334 (pos >= _size)) 00335 { 00336 return; 00337 } 00338 else 00339 { 00340 _data[pos] = 0; 00341 _size = pos; 00342 } 00343 } |
|
Definition at line 650 of file cmt_string.cxx. Referenced by operator+=(), replace(), and replace_all(). 00651 { 00652 if (_data != 0) n += _size; 00653 allocate (n); 00654 } |
|
Definition at line 292 of file cmt_string.cxx. 00293 { 00294 const char* text = other._data; 00295 return (find (pos, text)); 00296 } |
|
Definition at line 280 of file cmt_string.cxx. 00281 { 00282 if (_data == 0) return (npos); 00283 if (text == 0) return (npos); 00284 if (pos < 0) return (npos); 00285 if (pos >= _size) return (npos); 00286 00287 char* p = strstr (&_data[pos], text); 00288 if (p == 0) return (npos); 00289 return (p - _data); 00290 } |
|
Definition at line 269 of file cmt_string.cxx. 00270 { 00271 if (_data == 0) return (npos); 00272 if (pos < 0) return (npos); 00273 if (pos >= _size) return (npos); 00274 00275 char* p = strchr (&_data[pos], c); 00276 if (p == 0) return (npos); 00277 return (p - _data); 00278 } |
|
Definition at line 263 of file cmt_string.cxx. 00264 { 00265 const char* text = other._data; 00266 return (find (text)); 00267 } |
|
Definition at line 253 of file cmt_string.cxx. 00254 { 00255 if (_data == 0) return (npos); 00256 if (text == 0) return (npos); 00257 00258 char* p = strstr (_data, text); 00259 if (p == 0) return (npos); 00260 return (p - _data); 00261 } |
|
|
Definition at line 324 of file cmt_string.cxx. 00325 { 00326 const char* text = other._data; 00327 return (find_last_of (text)); 00328 } |
|
Definition at line 307 of file cmt_string.cxx. 00308 { 00309 if (_data == 0) return (npos); 00310 if (text == 0) return (npos); 00311 00312 char* ptr = _data; 00313 char* last = 0; 00314 char* p; 00315 while ((p = strstr (ptr, text)) != 0) 00316 { 00317 last = p; 00318 ptr = p + 1; 00319 } 00320 if (last == 0) return (npos); 00321 return (last - _data); 00322 } |
|
Definition at line 298 of file cmt_string.cxx. Referenced by CmtSystem::basename(), Generator::build_readme(), Generator::check(), Generator::commit(), CmtSystem::compress_path(), CmtSystem::dirname(), DependencyAnalyzer::filter(), find_last_of(), CmtSystem::get_dot_suffix(), CmtSystem::get_suffix(), CmtSystem::name(), Parser::parse_line(), and Cmt::parse_requirements_line(). 00299 { 00300 if (_data == 0) return (npos); 00301 00302 char* p = strrchr (_data, c); 00303 if (p == 0) return (npos); 00304 return (p - _data); 00305 } |
|
Definition at line 126 of file cmt_string.cxx. 00127 { 00128 if (_data == 0) return (""); 00129 else return (_data); 00130 } |
|
Definition at line 625 of file cmt_string.cxx. 00626 { 00627 const char* text = other._data; 00628 const cmt_string& me = *this; 00629 00630 return (me != text); 00631 } |
|
Definition at line 617 of file cmt_string.cxx. 00618 { 00619 const cmt_string& me = *this; 00620 00621 if (!(me == text)) return (true); 00622 return (false); 00623 } |
|
Definition at line 190 of file cmt_string.cxx. 00191 { 00192 cmt_string result (_data); 00193 result += other; 00194 00195 return (result); 00196 } |
|
Definition at line 182 of file cmt_string.cxx. 00183 { 00184 cmt_string result (_data); 00185 result += text; 00186 00187 return (result); 00188 } |
|
Definition at line 174 of file cmt_string.cxx. 00175 { 00176 cmt_string result (_data); 00177 result += c; 00178 00179 return (result); 00180 } |
|
Definition at line 166 of file cmt_string.cxx. 00167 { 00168 const char* text = other._data; 00169 cmt_string& me = *this; 00170 00171 me += text; 00172 } |
|
Definition at line 155 of file cmt_string.cxx. 00156 { 00157 if (text == 0) return; 00158 00159 int s = strlen (text); 00160 extend (s + 1); 00161 00162 strcat (&_data[_size], text); 00163 _size += s; 00164 } |
|
Definition at line 145 of file cmt_string.cxx. 00146 { 00147 extend (2); 00148 00149 char temp[2] = { c, 0 }; 00150 00151 strcat (&_data[_size], temp); 00152 _size++; 00153 } |
|
Definition at line 582 of file cmt_string.cxx. 00583 { 00584 const char* text = other._data; 00585 const cmt_string& me = *this; 00586 00587 return (me < text); 00588 } |
|
Definition at line 573 of file cmt_string.cxx. 00574 { 00575 if (text == 0) return (false); 00576 if (_data == 0) return (false); 00577 00578 if (strcmp (_data, text) < 0) return (true); 00579 return (false); 00580 } |
|
Definition at line 118 of file cmt_string.cxx. 00119 { 00120 const char* text = other._data; 00121 cmt_string& me = *this; 00122 me = text; 00123 return (me); 00124 } |
|
Definition at line 95 of file cmt_string.cxx. 00096 { 00097 if (text == _data) return (*this); 00098 00099 if (text != 0) 00100 { 00101 _size = strlen (text); 00102 allocate (_size + 1); 00103 strcpy (_data, text); 00104 } 00105 else 00106 { 00107 _size = 0; 00108 00109 if (_data != 0) 00110 { 00111 _data[0] = 0; 00112 } 00113 } 00114 00115 return (*this); 00116 } |
|
Definition at line 83 of file cmt_string.cxx. 00084 { 00085 allocate (2); 00086 00087 _data[0] = c; 00088 _data[1] = 0; 00089 00090 _size = 1; 00091 00092 return (*this); 00093 } |
|
Definition at line 609 of file cmt_string.cxx. 00610 { 00611 const char* text = other._data; 00612 const cmt_string& me = *this; 00613 00614 return (me == text); 00615 } |
|
Definition at line 590 of file cmt_string.cxx. 00591 { 00592 if (text == 0) 00593 { 00594 if (_data == 0) return (true); 00595 if (_size == 0) return (true); 00596 return (false); 00597 } 00598 if (_data == 0) 00599 { 00600 if (text == 0) return (true); 00601 if (strlen (text) == 0) return (true); 00602 return (false); 00603 } 00604 00605 if (strcmp (_data, text) == 0) return (true); 00606 return (false); 00607 } |
|
Definition at line 642 of file cmt_string.cxx. 00643 { 00644 const char* text = other._data; 00645 const cmt_string& me = *this; 00646 00647 return (me > text); 00648 } |
|
Definition at line 633 of file cmt_string.cxx. 00634 { 00635 if (text == 0) return (false); 00636 if (_data == 0) return (false); 00637 00638 if (strcmp (_data, text) > 0) return (true); 00639 return (false); 00640 } |
|
Definition at line 212 of file cmt_string.cxx. 00213 { 00214 if ((_data == 0) || 00215 (index < 0) || 00216 (index >= _size)) 00217 { 00218 static char temp; 00219 return (temp); 00220 } 00221 else 00222 { 00223 return (_data[index]); 00224 } 00225 } |
|
Definition at line 198 of file cmt_string.cxx. 00199 { 00200 if ((_data == 0) || 00201 (index < 0) || 00202 (index >= _size)) 00203 { 00204 return (0); 00205 } 00206 else 00207 { 00208 return (_data[index]); 00209 } 00210 } |
|
Definition at line 712 of file cmt_string.cxx. Referenced by add_cmt_paths(), Generator::build_default_makefile(), Generator::build_dependencies(), CmtLock::check(), CmtSystem::compare_and_update_files(), CmtSystem::compare_files(), Cmt::configure_current_dir(), Fragment::copy(), Cmt::do_filter(), Cmt::parse_requirements(), CvsImplementation::really_checkout_package(), PackageCollector::run(), FAwk::run(), and Fragment::wincopy(). 00713 { 00714 FILE* f = fopen (file_name.c_str (), "rb"); 00715 if (f != NULL) 00716 { 00717 fseek (f, 0L, SEEK_END); 00718 int size = ftell (f); 00719 fseek (f, 0L, SEEK_SET); 00720 00721 allocate (size + 1); 00722 00723 fread (&_data[0], size, 1, f); 00724 00725 _data[size] = 0; 00726 _size = size; 00727 00728 fclose (f); 00729 00730 return (true); 00731 } 00732 else 00733 { 00734 cmt_string& me = *this; 00735 me = ""; 00736 00737 return (false); 00738 } 00739 } |
|
Definition at line 423 of file cmt_string.cxx. 00425 { 00426 const char* p_text = pattern._data; 00427 const char* r_text = replacement._data; 00428 cmt_string& me = *this; 00429 00430 me.replace (p_text, r_text); 00431 } |
|
Definition at line 369 of file cmt_string.cxx. Referenced by Fragment::action(), add_line_to_text(), MacroBuilder::build(), Cmt::configure_current_dir(), DependencyAnalyzer::filter(), TriggerAnalyzer::filter(), Prototyper::filter(), CvsImplementation::get_version(), header_file_action(), Fragment::print(), replace(), resolve_value_for_macros(), PackageSelector::run(), PAwk::run(), Use::show_all(), CvsImplementation::show_cvs_infos(), and suppress_OS_delimiters(). 00370 { 00371 if (_data == 0) return; 00372 if (_size == 0) return; 00373 if (pattern == 0) return; 00374 00375 if (replacement == 0) replacement = ""; 00376 00377 int pattern_length = strlen (pattern); 00378 00379 if (pattern_length == 0) return; 00380 00381 int replacement_length = strlen (replacement); 00382 int delta = replacement_length - pattern_length; 00383 00384 int pos; 00385 00386 if ((pos = find (pattern)) != npos) 00387 { 00388 if (delta > 0) 00389 { 00390 // string will be enlarged 00391 extend (delta); 00392 00393 char* src = &_data[_size]; 00394 char* dest = src + delta; 00395 while (src > &_data[pos]) 00396 { 00397 *dest = *src; 00398 src--; 00399 dest--; 00400 } 00401 } 00402 else if (delta < 0) 00403 { 00404 // string will be shortened 00405 00406 char* src = &_data[pos + pattern_length]; 00407 char* dest = src + delta; 00408 while (*src != 0) 00409 { 00410 *dest = *src; 00411 src++; 00412 dest++; 00413 } 00414 *dest = *src; 00415 } 00416 00417 strncpy (&_data[pos], replacement, replacement_length); 00418 00419 _size += delta; 00420 } 00421 } |
|
Definition at line 486 of file cmt_string.cxx. 00488 { 00489 const char* p_text = pattern._data; 00490 const char* r_text = replacement._data; 00491 cmt_string& me = *this; 00492 00493 me.replace_all (p_text, r_text); 00494 } |
|
Definition at line 433 of file cmt_string.cxx. Referenced by DependencyAnalyzer::DependencyAnalyzer(), CmtSystem::add_cmt_path(), DepsBuilder::add_includes(), MacroBuilder::build(), PathBuilder::build(), SetBuilder::build(), MakefileGenerator::build_library_makefile(), CvsImplementation::build_version_directory(), CvsImplementation::checkout(), PathBuilder::clean(), CmtSystem::compress_path(), Fragment::copy(), CmtModel::display(), Pattern::expand(), DependencyAnalyzer::filter(), CmtModel::filter(), Packager::filter(), filter_paths(), CvsImplementation::get_version(), CmtSystem::mkdir(), CmtSystem::now(), Cmt::parse_requirements_line(), MakefileGenerator::prepare_use_context(), Symbol::print(), replace_all(), Symbol::resolve_macro_value(), resolve_value(), resolve_value_for_macros(), SourceFile::set(), MakefileGenerator::set_full_name(), CvsImplementation::show_cvs_infos(), and Fragment::wincopy(). 00434 { 00435 if (_data == 0) return; 00436 if (_size == 0) return; 00437 if (pattern == 0) return; 00438 00439 if (replacement == 0) replacement = ""; 00440 00441 int pattern_length = strlen (pattern); 00442 if (pattern_length == 0) return; 00443 00444 int replacement_length = strlen (replacement); 00445 int delta = replacement_length - pattern_length; 00446 00447 int pos = 0; 00448 00449 while ((pos = find (pos, pattern)) != npos) 00450 { 00451 if (delta > 0) 00452 { 00453 // string will be enlarged 00454 extend (delta); 00455 00456 char* src = &_data[_size]; 00457 char* dest = src + delta; 00458 while (src > &_data[pos]) 00459 { 00460 *dest = *src; 00461 src--; 00462 dest--; 00463 } 00464 } 00465 else if (delta < 0) 00466 { 00467 // string will be shortened 00468 00469 char* src = &_data[pos + pattern_length]; 00470 char* dest = src + delta; 00471 while (*src != 0) 00472 { 00473 *dest = *src; 00474 src++; 00475 dest++; 00476 } 00477 *dest = *src; 00478 } 00479 00480 strncpy (&_data[pos], replacement, replacement_length); 00481 pos += replacement_length; 00482 _size += delta; 00483 } 00484 } |
|
Definition at line 239 of file cmt_string.cxx. 00240 { 00241 allocate (n + 1); 00242 } |
|
Definition at line 233 of file cmt_string.cxx. 00234 { 00235 if (_data == 0) return (0); 00236 return (_size); 00237 } |
|
|
Definition at line 558 of file cmt_string.cxx. 00559 { 00560 if ((_data == 0) || 00561 (pos < 0) || 00562 (pos >= _size)) 00563 { 00564 dest = ""; 00565 } 00566 else 00567 { 00568 dest = (const char*) &_data[pos]; 00569 dest.erase (length); 00570 } 00571 } |
|
Definition at line 544 of file cmt_string.cxx. 00545 { 00546 if ((_data == 0) || 00547 (pos < 0) || 00548 (pos >= _size)) 00549 { 00550 dest = ""; 00551 } 00552 else 00553 { 00554 dest = (const char*) &_data[pos]; 00555 } 00556 } |
|
Definition at line 528 of file cmt_string.cxx. 00529 { 00530 if ((_data == 0) || 00531 (pos < 0) || 00532 (pos >= _size)) 00533 { 00534 return ((cmt_string) ""); 00535 } 00536 else 00537 { 00538 cmt_string result (&_data[pos]); 00539 result.erase (length); 00540 return (result); 00541 } 00542 } |
|
Definition at line 514 of file cmt_string.cxx. Referenced by ApplyPattern::action(), Language::action(), DepsBuilder::add_includes(), add_line_to_text(), CmtSystem::basename(), Generator::build_readme(), CmtSystem::compress_path(), Cmt::configure_current_dir(), Cmt::do_broadcast(), CmtModel::expand(), DependencyAnalyzer::filter(), TriggerAnalyzer::filter(), CmtSystem::get_dot_suffix(), CmtSystem::get_suffix(), cmt_string_node::match(), Parser::parse(), Cmt::parse_arguments(), Cmt::parse_requirements_text(), Symbol::resolve_macro_value(), resolve_value(), resolve_value_for_macros(), PackageCollector::run(), Awk::run(), constituents_action_iterator::set(), Libmap::set_used(), suppress_OS_delimiters(), and Fragment::wincopy(). 00515 { 00516 if ((_data == 0) || 00517 (pos < 0) || 00518 (pos >= _size)) 00519 { 00520 return ((cmt_string) ""); 00521 } 00522 else 00523 { 00524 return ((cmt_string) &_data[pos]); 00525 } 00526 } |
|
Definition at line 496 of file cmt_string.cxx. Referenced by DependencyAnalyzer::filter(). 00497 { 00498 if (size () == 0) return; 00499 00500 int i = 0; 00501 00502 i = strspn (_data, " \t"); 00503 if (i > 0) erase (0, i); 00504 00505 for (i = _size - 1; i >= 0; i--) 00506 { 00507 char c = _data[i]; 00508 if ((c == ' ') || (c == '\t')) continue; 00509 erase (i + 1); 00510 break; 00511 } 00512 } |
|
Definition at line 761 of file cmt_string.cxx. 00762 { 00763 output.write (&_data[0], size ()); 00764 } |
|
Definition at line 756 of file cmt_string.cxx. 00757 { 00758 fwrite (&_data[0], size (), 1, f); 00759 } |
|
Definition at line 741 of file cmt_string.cxx. Referenced by Generator::build_default_makefile(), Generator::build_dependencies(), CmtSystem::compare_and_update_files(), Fragment::copy(), Cmt::do_filter(), CmtLock::lock(), and Fragment::wincopy(). 00742 { 00743 FILE* f = fopen (file_name.c_str (), "wb"); 00744 if (f != NULL) 00745 { 00746 write (f); 00747 fclose (f); 00748 return (true); 00749 } 00750 else 00751 { 00752 return (false); 00753 } 00754 } |
|
Definition at line 105 of file cmt_string.h. |
|
Definition at line 104 of file cmt_string.h. |
|
Definition at line 106 of file cmt_string.h. |