Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

cmt_string Class Reference

#include <cmt_string.h>

List of all members.

Public Types

enum  pos_type { npos = -1 }

Public Member Functions

 cmt_string ()
 cmt_string (int n)
 cmt_string (char c)
 cmt_string (const char *text)
 cmt_string (const cmt_string &other)
 ~cmt_string ()
cmt_stringoperator= (char c)
cmt_stringoperator= (const char *text)
cmt_stringoperator= (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 Member Functions

void extend (int n)
void allocate (int n)

Private Attributes

char * _data
int _allocated
int _size


Member Enumeration Documentation

enum cmt_string::pos_type
 

Enumeration values:
npos 

Definition at line 16 of file cmt_string.h.

00017     {
00018       npos = -1
00019     } pos_type;


Constructor & Destructor Documentation

cmt_string::cmt_string  ) 
 

Definition at line 12 of file cmt_string.cxx.

References _allocated, _data, and _size.

00013 {
00014   _data = 0;
00015   _allocated = 0;
00016   _size = 0;
00017 }

cmt_string::cmt_string int  n  ) 
 

Definition at line 19 of file cmt_string.cxx.

References _allocated, _data, _size, and allocate().

00020 {
00021   _data = 0;
00022   _allocated = 0;
00023   _size = 0;
00024   allocate (n + 1);
00025 }

cmt_string::cmt_string char  c  ) 
 

Definition at line 27 of file cmt_string.cxx.

References _allocated, _data, _size, and allocate().

00028 {
00029   _data = 0;
00030   _allocated = 0;
00031   _size = 0;
00032 
00033   allocate (2);
00034 
00035   _data[0] = c;
00036   _data[1] = 0;
00037   _size = 1;
00038 }

cmt_string::cmt_string const char *  text  ) 
 

Definition at line 40 of file cmt_string.cxx.

References _allocated, _data, _size, and allocate().

00041 {
00042   _data = 0;
00043   _allocated = 0;
00044   _size = 0;
00045 
00046   if (text != 0)
00047     {
00048       _size = strlen (text);
00049       allocate (_size + 1);
00050       strcpy (_data, text);
00051     }
00052 }

cmt_string::cmt_string const cmt_string other  ) 
 

Definition at line 54 of file cmt_string.cxx.

References _allocated, _data, _size, and allocate().

00055 {
00056   const char* text = other._data;
00057 
00058   _data = 0;
00059   _allocated = 0;
00060   _size = 0;
00061 
00062   if (text != 0)
00063     {
00064       _size = strlen (text);
00065       allocate (_size + 1);
00066       strcpy (_data, text);
00067     }
00068 }

cmt_string::~cmt_string  ) 
 

Definition at line 70 of file cmt_string.cxx.

References _allocated, _data, and _size.

00071 {
00072   if (_data != 0)
00073     {
00074 #ifdef CMT_USE_NEW_DELETE
00075       delete[] _data;
00076 #else
00077       free (_data);
00078 #endif
00079     }
00080   _data = 0;
00081   _allocated = 0;
00082   _size = 0;
00083 }


Member Function Documentation

void cmt_string::allocate int  n  )  [private]
 

Definition at line 670 of file cmt_string.cxx.

References _allocated, and _data.

Referenced by cmt_string(), extend(), operator=(), read(), and resize().

00671 {
00672   if ((n + 1) > _allocated)
00673     {
00674       static const int quantum = 128;
00675       int frames = ((n + 1)/quantum) + 1;
00676       _allocated = frames * quantum;
00677 
00678 #ifdef CMT_USE_NEW_DELETE
00679       char* new_data = new char [_allocated + 1];
00680 #else
00681       char* new_data = (char*) malloc (_allocated + 1);
00682 #endif
00683 
00684 
00685       if (_data != 0)
00686         {
00687           strcpy (new_data, _data);
00688 
00689 #ifdef CMT_USE_NEW_DELETE
00690           delete[] _data;
00691 #else
00692           free (_data);
00693 #endif
00694 
00695           _data = new_data;
00696         }
00697       else
00698         {
00699           new_data[0] = 0;
00700         }
00701 
00702       _data = new_data;
00703     }
00704 }

const char * cmt_string::c_str  )  const
 

Definition at line 137 of file cmt_string.cxx.

References _data.

Referenced by Prototyper::begin(), DependencyGenerator::build(), MakeSetupGenerator::build(), DefaultMakefileGenerator::build(), ReadmeGenerator::build(), DocumentGenerator::build(), LibraryGenerator::build(), build_deps(), CmtSystem::cd(), CmtGenerator::check(), CmtGenerator::commit(), CmtSystem::compare_and_update_files(), CmtSystem::compare_files(), CmtSystem::create_symlink(), Cmt::do_broadcast(), dos_script_prefix(), CmtSystem::execute(), Pattern::expand(), CmtPathPattern::expand(), CmtSystem::file_size(), Prototyper::filter(), Cmt::install_cleanup_scripts(), Cmt::install_setup_scripts(), Cmt::install_test_cleanup_scripts(), Cmt::install_test_setup_scripts(), CmtSystem::is_version_directory(), Cmt::load(), CmtSystem::mkdir(), Cmt::parser(), CmtGenerator::prepare_output(), CmtSystem::putenv(), read(), PackageSelector::run(), PAwk::run(), CmtSystem::scan_dir(), CmtSystem::split(), CmtSystem::test_directory(), CmtSystem::test_file(), and write().

00138 {
00139   if (_data == 0) return ("");
00140   else return (_data);
00141 }

bool cmt_string::compare_no_case const cmt_string other  )  const
 

bool cmt_string::compare_no_case const char *  text  )  const
 

void cmt_string::erase int  pos,
int  length
 

Definition at line 350 of file cmt_string.cxx.

References _data, and _size.

00351 {
00352   if ((_data == 0) ||
00353       (pos < 0) ||
00354       (pos >= _size))
00355     {
00356       return;
00357     }
00358   else
00359     {
00360       if ((pos + length) >= _size)
00361         {
00362           _data[pos] = 0;
00363           _size = pos;
00364         }
00365       else if (length > 0)
00366         {
00367           char* d = &_data[pos];
00368           char* s = &_data[pos + length];
00369           for (;;)
00370             {
00371               *d = *s;
00372               if (*s == 0) break;
00373               d++;
00374               s++;
00375             }
00376           _size -= length;
00377         }
00378     }
00379 }

void cmt_string::erase int  pos  ) 
 

Definition at line 335 of file cmt_string.cxx.

References _data, and _size.

Referenced by ApplyPattern::action(), Language::action(), Script::add(), DepsBuilder::add(), add_cmt_paths_from_file(), DependencyGenerator::add_line_to_text(), CmtSystem::basename(), SetBuilder::build(), ConstituentsMakefileGenerator::build(), ReadmeGenerator::build(), CmtGenerator::check(), CmtGenerator::commit(), CmtSystem::compress_path(), CmtInstallAreaMgr::config(), Cmt::configure_current_package(), CmtSystem::dirname(), CMTPathManager::do_add_cmt_path(), Cmt::do_broadcast(), ArgParser::do_lock(), SyntaxParser::do_parse_line(), SyntaxParser::do_parse_text(), ArgParser::do_remove(), ArgParser::do_unlock(), Pattern::expand(), CmtModel::expand(), DependencyFilter::filter(), Packager::filter(), WinDefAwk::filter(), CvsImplementation::make_management_files(), CmtSystem::name(), ArgParser::option_tag_remove(), ArgParser::parse(), Parser::parse(), Parser::parse_line(), Use::reach_package(), resolve_value(), resolve_value_for_macros(), ClientCollector::run(), CmtSystem::scan_dir(), PathScanner::scan_package(), PathScanner::scan_path(), use_action_iterator::set(), constituents_action_iterator::set(), Use::show_all(), CmtModel::strict_expand(), substr(), suppress_OS_delimiters(), trim(), and Cmt::vector_to_string().

00336 {
00337   if ((_data == 0) ||
00338       (pos < 0) ||
00339       (pos >= _size))
00340     {
00341       return;
00342     }
00343   else
00344     {
00345       _data[pos] = 0;
00346       _size = pos;
00347     }
00348 }

void cmt_string::extend int  n  )  [private]
 

Definition at line 664 of file cmt_string.cxx.

References _data, _size, and allocate().

Referenced by operator+=(), replace(), and replace_all().

00665 {
00666   if (_data != 0) n += _size;
00667   allocate (n);
00668 }

int cmt_string::find int  pos,
const cmt_string other
const
 

Definition at line 297 of file cmt_string.cxx.

References _data, and find().

00298 {
00299   const char* text = other._data;
00300   return (find (pos, text));
00301 }

int cmt_string::find int  pos,
const char *  text
const
 

Definition at line 285 of file cmt_string.cxx.

References _data, _size, and npos.

00286 {
00287   if (_data == 0) return (npos);
00288   if (text == 0) return (npos);
00289   if (pos < 0) return (npos);
00290   if (pos >= _size) return (npos);
00291 
00292   char* p = strstr (&_data[pos], text);
00293   if (p == 0) return (npos);
00294   return (p - _data);
00295 }

int cmt_string::find int  pos,
char  c
const
 

Definition at line 274 of file cmt_string.cxx.

References _data, _size, and npos.

00275 {
00276   if (_data == 0) return (npos);
00277   if (pos < 0) return (npos);
00278   if (pos >= _size) return (npos);
00279 
00280   char* p = strchr (&_data[pos], c);
00281   if (p == 0) return (npos);
00282   return (p - _data);
00283 }

int cmt_string::find const cmt_string other  )  const
 

Definition at line 268 of file cmt_string.cxx.

References _data, and find().

00269 {
00270   const char* text = other._data;
00271   return (find (text));
00272 }

int cmt_string::find const char *  text  )  const
 

Definition at line 258 of file cmt_string.cxx.

References _data, and npos.

00259 {
00260   if (_data == 0) return (npos);
00261   if (text == 0) return (npos);
00262 
00263   char* p = strstr (_data, text);
00264   if (p == 0) return (npos);
00265   return (p - _data);
00266 }

int cmt_string::find char  c  )  const
 

Definition at line 249 of file cmt_string.cxx.

References _data, and npos.

Referenced by Symbol::action(), ApplyPattern::action(), Tag::add(), Script::add(), Pattern::add(), CmtPathPattern::add(), add_cmt_paths_from_file(), CvsImplementation::add_cmtpath(), DepsBuilder::add_includes(), DependencyGenerator::add_line_to_text(), DependencyFilter::add_source(), CmtPathPattern::apply(), PathBuilder::build(), DependencyGenerator::build(), DefaultMakefileGenerator::build(), VSNETGenerator::build_project(), CvsImplementation::check_protocol(), PathBuilder::clean(), CmtSystem::compress_path(), CmtInstallAreaMgr::config(), Cmt::configure_current_package(), ProjectFactory::create_project(), Cmt::do_broadcast(), CvsImplementation::do_checkout_phase2(), SyntaxParser::do_parse_text(), Pattern::expand(), CmtModel::expand(), DependencyAnalyzer::filter(), TriggerAnalyzer::filter(), CmtMountFilterParser::filter(), DependencyFilter::filter(), Prototyper::filter(), Packager::filter(), WinDefAwk::filter(), RecursivePass4::filter(), RecursivePass3::filter(), RecursivePass2::filter(), RecursivePass1::filter(), find(), Project::find_in_cmt_paths(), CvsImplementation::find_matching_version(), CmtGenerator::get_all_files(), Project::get_current(), CvsImplementation::get_cvs_infos(), CvsImplementation::get_version(), CmtSystem::has_prefix(), DependencyFilter::has_source(), History::is_installed(), CmtSystem::is_version_directory(), CvsImplementation::make_management_files(), ArgParser::option_tag(), ArgParser::option_tag_add(), ArgParser::option_tag_remove(), ArgParser::parse(), Parser::parse(), Parser::parse_line(), Script::print(), Use::reach_package(), CmtSystem::reduce_file_separators(), replace(), replace_all(), resolve_value(), resolve_value_for_macros(), ClientCollector::run(), PAwk::run(), Awk::run(), CmtSystem::scan_dir(), PathScanner::scan_package(), PathScanner::scan_path(), constituents_action_iterator::set(), Libmap::set_used(), Project::show(), CmtModel::strict_expand(), suppress_OS_delimiters(), and Fragment::wincopy().

00250 {
00251   if (_data == 0) return (npos);
00252 
00253   char* p = strchr (_data, c);
00254   if (p == 0) return (npos);
00255   return (p - _data);
00256 }

int cmt_string::find_last_of const cmt_string other  )  const
 

Definition at line 329 of file cmt_string.cxx.

References _data, and find_last_of().

00330 {
00331   const char* text = other._data;
00332   return (find_last_of (text));
00333 }

int cmt_string::find_last_of const char *  text  )  const
 

Definition at line 312 of file cmt_string.cxx.

References _data, and npos.

00313 {
00314   if (_data == 0) return (npos);
00315   if (text == 0) return (npos);
00316 
00317   char* ptr = _data;
00318   char* last = 0;
00319   char* p;
00320   while ((p = strstr (ptr, text)) != 0)
00321     {
00322       last = p;
00323       ptr = p + 1;
00324     }
00325   if (last == 0) return (npos);
00326   return (last - _data);
00327 }

int cmt_string::find_last_of char  c  )  const
 

Definition at line 303 of file cmt_string.cxx.

References _data, and npos.

Referenced by CmtSystem::basename(), ReadmeGenerator::build(), CmtGenerator::check(), CmtGenerator::commit(), CmtSystem::compress_path(), CmtSystem::dirname(), SyntaxParser::do_parse_line(), DependencyAnalyzer::filter(), find_last_of(), CmtSystem::get_dot_suffix(), CmtSystem::get_suffix(), CmtSystem::name(), Parser::parse_line(), and Use::show_all().

00304 {
00305   if (_data == 0) return (npos);
00306 
00307   char* p = strrchr (_data, c);
00308   if (p == 0) return (npos);
00309   return (p - _data);
00310 }

cmt_string::operator const char *  )  const
 

Definition at line 131 of file cmt_string.cxx.

References _data.

00132 {
00133   if (_data == 0) return ("");
00134   else return (_data);
00135 }

bool cmt_string::operator!= const cmt_string other  )  const
 

Definition at line 639 of file cmt_string.cxx.

References _data.

00640 {
00641   const char* text = other._data;
00642   const cmt_string& me = *this;
00643 
00644   return (me != text);
00645 }

bool cmt_string::operator!= const char *  text  )  const
 

Definition at line 631 of file cmt_string.cxx.

00632 {
00633   const cmt_string& me = *this;
00634 
00635   if (!(me == text)) return (true);
00636   return (false);
00637 }

cmt_string cmt_string::operator+ const cmt_string other  )  const
 

Definition at line 195 of file cmt_string.cxx.

References _data.

00196 {
00197   cmt_string result (_data);
00198   result += other;
00199 
00200   return (result);
00201 }

cmt_string cmt_string::operator+ const char *  text  )  const
 

Definition at line 187 of file cmt_string.cxx.

References _data.

00188 {
00189   cmt_string result (_data);
00190   result += text;
00191 
00192   return (result);
00193 }

cmt_string cmt_string::operator+ char  c  )  const
 

Definition at line 179 of file cmt_string.cxx.

References _data.

00180 {
00181   cmt_string result (_data);
00182   result += c;
00183 
00184   return (result);
00185 }

void cmt_string::operator+= const cmt_string other  ) 
 

Definition at line 171 of file cmt_string.cxx.

References _data.

00172 {
00173   const char* text = other._data;
00174   cmt_string& me = *this;
00175 
00176   me += text;
00177 }

void cmt_string::operator+= const char *  text  ) 
 

Definition at line 160 of file cmt_string.cxx.

References _data, _size, and extend().

00161 {
00162   if (text == 0) return;
00163 
00164   int s = strlen (text);
00165   extend (s + 1);
00166 
00167   strcat (&_data[_size], text);
00168   _size += s;
00169 }

void cmt_string::operator+= char  c  ) 
 

Definition at line 150 of file cmt_string.cxx.

References _data, _size, and extend().

00151 {
00152   extend (2);
00153 
00154   char temp[2] = { c, 0 };
00155 
00156   strcat (&_data[_size], temp);
00157   _size++;
00158 }

bool cmt_string::operator< const cmt_string other  )  const
 

Definition at line 596 of file cmt_string.cxx.

References _data.

00597 {
00598   const char* text = other._data;
00599   const cmt_string& me = *this;
00600 
00601   return (me < text);
00602 }

bool cmt_string::operator< const char *  text  )  const
 

Definition at line 587 of file cmt_string.cxx.

References _data.

00588 {
00589   if (text == 0) return (false);
00590   if (_data == 0) return (false);
00591 
00592   if (strcmp (_data, text) < 0) return (true);
00593   return (false);
00594 }

cmt_string & cmt_string::operator= const cmt_string other  ) 
 

Definition at line 123 of file cmt_string.cxx.

References _data.

00124 {
00125   const char* text = other._data;
00126   cmt_string& me = *this;
00127   me = text;
00128   return (me);
00129 }

cmt_string & cmt_string::operator= const char *  text  ) 
 

Definition at line 100 of file cmt_string.cxx.

References _data, _size, and allocate().

00101 {
00102   if (text == _data) return (*this);
00103 
00104   if (text != 0)
00105     {
00106       _size = strlen (text);
00107       allocate (_size + 1);
00108       strcpy (_data, text);
00109     }
00110   else
00111     {
00112       _size = 0;
00113 
00114       if (_data != 0)
00115         {
00116           _data[0] = 0;
00117         }
00118     }
00119 
00120   return (*this);
00121 }

cmt_string & cmt_string::operator= char  c  ) 
 

Definition at line 88 of file cmt_string.cxx.

References _data, _size, and allocate().

00089 {
00090   allocate (2);
00091 
00092   _data[0] = c;
00093   _data[1] = 0;
00094 
00095   _size = 1;
00096 
00097   return (*this);
00098 }

bool cmt_string::operator== const cmt_string other  )  const
 

Definition at line 623 of file cmt_string.cxx.

References _data.

00624 {
00625   const char* text = other._data;
00626   const cmt_string& me = *this;
00627 
00628   return (me == text);
00629 }

bool cmt_string::operator== const char *  text  )  const
 

Definition at line 604 of file cmt_string.cxx.

References _data, and _size.

00605 {
00606   if (text == 0)
00607     {
00608       if (_data == 0) return (true);
00609       if (_size == 0) return (true);
00610       return (false);
00611     }
00612   if (_data == 0)
00613     {
00614       if (text == 0) return (true);
00615       if (text[0] == 0) return (true);
00616       return (false);
00617     }
00618 
00619   if (strcmp (_data, text) == 0) return (true);
00620   return (false);
00621 }

bool cmt_string::operator> const cmt_string other  )  const
 

Definition at line 656 of file cmt_string.cxx.

References _data.

00657 {
00658   const char* text = other._data;
00659   const cmt_string& me = *this;
00660 
00661   return (me > text);
00662 }

bool cmt_string::operator> const char *  text  )  const
 

Definition at line 647 of file cmt_string.cxx.

References _data.

00648 {
00649   if (text == 0) return (false);
00650   if (_data == 0) return (false);
00651 
00652   if (strcmp (_data, text) > 0) return (true);
00653   return (false);
00654 }

char & cmt_string::operator[] int  index  ) 
 

Definition at line 217 of file cmt_string.cxx.

References _data, and _size.

00218 {
00219   if ((_data == 0) ||
00220       (index < 0) ||
00221       (index >= _size))
00222     {
00223       static char temp;
00224       return (temp);
00225     }
00226   else
00227     {
00228       return (_data[index]);
00229     }
00230 }

char cmt_string::operator[] int  index  )  const
 

Definition at line 203 of file cmt_string.cxx.

References _data, and _size.

00204 {
00205   if ((_data == 0) ||
00206       (index < 0) ||
00207       (index >= _size))
00208     {
00209       return (0);
00210     }
00211   else
00212     {
00213       return (_data[index]);
00214     }
00215 }

bool cmt_string::read const cmt_string file_name  ) 
 

Definition at line 726 of file cmt_string.cxx.

References _data, _size, allocate(), c_str(), and size().

Referenced by add_cmt_paths_from_file(), DependencyGenerator::build(), DefaultMakefileGenerator::build(), CmtLock::check(), CvsImplementation::checkout_from_project_file(), CvsImplementation::checkout_from_requirements(), CmtSystem::compare_and_update_files(), CmtSystem::compare_files(), CmtInstallAreaMgr::config(), Cmt::configure_current_package(), Fragment::copy(), Project::create(), ProjectFactory::create_project(), Cmt::do_awk(), Cmt::do_build_CMT_pacman(), Cmt::do_filter(), SyntaxParser::do_parse_requirements(), Cmt::do_remove(), CvsImplementation::make_management_files(), Use::reach_package(), ClientCollector::run(), FAwk::run(), PathScanner::scan_package(), PathScanner::scan_path(), and Fragment::wincopy().

00727 {
00728   FILE* f = fopen (file_name.c_str (), "rb");
00729   if (f != NULL)
00730     {
00731       fseek (f, 0L, SEEK_END);
00732       int size = ftell (f);
00733       fseek (f, 0L, SEEK_SET);
00734 
00735       allocate (size + 1);
00736 
00737       fread (&_data[0], size, 1, f);
00738 
00739       _data[size] = 0;
00740       _size = size;
00741 
00742       fclose (f);
00743 
00744       return (true);
00745     }
00746   else
00747     {
00748       cmt_string& me = *this;
00749       me = "";
00750 
00751       return (false);
00752     }
00753 }

void cmt_string::replace const cmt_string pattern,
const cmt_string replacement
 

Definition at line 436 of file cmt_string.cxx.

References _data, and replace().

00438 {
00439   const char* p_text = pattern._data;
00440   const char* r_text = replacement._data;
00441   cmt_string& me = *this;
00442 
00443   me.replace (p_text, r_text);
00444 }

void cmt_string::replace const char *  pattern,
const char *  replacement
 

Definition at line 382 of file cmt_string.cxx.

References _data, _size, extend(), find(), and npos.

Referenced by DependencyGenerator::add_line_to_text(), fragment_action_iterator::add_word(), LibraryGenerator::analyze_file(), Cmt::configure_current_cmtpath(), Cmt::do_broadcast(), DependencyAnalyzer::filter(), TriggerAnalyzer::filter(), SequenceRunner::filter(), CmtMountFilterParser::filter(), Prototyper::filter(), CvsImplementation::find_matching_version(), Use::get_cmtpath_and_offset(), CvsImplementation::get_cvs_infos_with_offset(), CvsImplementation::get_version(), header_file_action(), Use::reduce_path(), replace(), resolve_value_for_macros(), PackageSelector::run(), PAwk::run(), and suppress_OS_delimiters().

00383 {
00384   if (_data == 0) return;
00385   if (_size == 0) return;
00386   if (pattern == 0) return;
00387 
00388   if (replacement == 0) replacement = "";
00389 
00390   if (pattern[0] == 0) return;
00391 
00392   int pattern_length = strlen (pattern);
00393 
00394   int replacement_length = strlen (replacement);
00395   int delta = replacement_length - pattern_length;
00396 
00397   int pos;
00398 
00399   if ((pos = find (pattern)) != npos)
00400     {
00401       if (delta > 0)
00402         {
00403             // string will be enlarged
00404           extend (delta);
00405 
00406           char* src = &_data[_size];
00407           char* dest = src + delta;
00408           while (src > &_data[pos])
00409             {
00410               *dest = *src;
00411               src--;
00412               dest--;
00413             }
00414         }
00415       else if (delta < 0)
00416         {
00417             // string will be shortened
00418 
00419           char* src = &_data[pos + pattern_length];
00420           char* dest = src + delta;
00421           while (*src != 0)
00422             {
00423               *dest = *src;
00424               src++;
00425               dest++;
00426             }
00427           *dest = *src;
00428         }
00429 
00430       strncpy (&_data[pos], replacement, replacement_length);
00431 
00432       _size += delta;
00433     }
00434 }

void cmt_string::replace_all const cmt_string pattern,
const cmt_string replacement
 

Definition at line 500 of file cmt_string.cxx.

References _data, and replace_all().

00502 {
00503   const char* p_text = pattern._data;
00504   const char* r_text = replacement._data;
00505   cmt_string& me = *this;
00506 
00507   me.replace_all (p_text, r_text);
00508 }

void cmt_string::replace_all const char *  pattern,
const char *  replacement
 

Definition at line 446 of file cmt_string.cxx.

References _data, _size, extend(), find(), and npos.

Referenced by DepsBuilder::add_includes(), Symbol::all_set(), PathBuilder::build(), SetBuilder::build(), LibraryGenerator::build(), CvsImplementation::checkout(), PathBuilder::clean(), CmtSystem::compress_path(), CmtInstallAreaMgr::config(), Fragment::copy(), DependencyAnalyzer::DependencyAnalyzer(), CmtModel::display(), CMTPathManager::do_add_cmt_path(), Cmt::do_broadcast(), Cmt::do_build_CMT_pacman(), SyntaxParser::do_parse_line(), Pattern::expand(), CmtPathPattern::expand(), DependencyAnalyzer::filter(), CmtModel::filter(), Packager::filter(), WinDefAwk::filter(), CmtGenerator::filter_path(), CmtSystem::get_cmt_root(), CmtSystem::get_cmt_version(), CvsImplementation::get_cvs_infos(), CvsImplementation::get_cvs_infos_with_offset(), CvsImplementation::get_version(), CmtSystem::mkdir(), CmtSystem::now(), Cmt::print_context(), CmtSystem::reduce_file_separators(), replace_all(), resolve_value(), resolve_value_for_macros(), CvsImplementation::retreive_cvs_infos(), DepsBuilder::run(), PathScanner::scan_path(), ApplyPattern::show(), suppress_OS_delimiters(), CvsImplementation::tags(), and Fragment::wincopy().

00447 {
00448   if (_data == 0) return;
00449   if (_size == 0) return;
00450   if (pattern == 0) return;
00451 
00452   if (replacement == 0) replacement = "";
00453 
00454   if (pattern[0] == 0) return;
00455 
00456   int pattern_length = strlen (pattern);
00457 
00458   int replacement_length = strlen (replacement);
00459   int delta = replacement_length - pattern_length;
00460 
00461   int pos = 0;
00462 
00463   while ((pos = find (pos, pattern)) != npos)
00464     {
00465       if (delta > 0)
00466         {
00467             // string will be enlarged
00468           extend (delta);
00469 
00470           char* src = &_data[_size];
00471           char* dest = src + delta;
00472           while (src > &_data[pos])
00473             {
00474               *dest = *src;
00475               src--;
00476               dest--;
00477             }
00478         }
00479       else if (delta < 0)
00480         {
00481             // string will be shortened
00482 
00483           char* src = &_data[pos + pattern_length];
00484           char* dest = src + delta;
00485           while (*src != 0)
00486             {
00487               *dest = *src;
00488               src++;
00489               dest++;
00490             }
00491           *dest = *src;
00492         }
00493 
00494       strncpy (&_data[pos], replacement, replacement_length);
00495       pos += replacement_length;
00496       _size += delta;
00497     }
00498 }

void cmt_string::resize int  n  ) 
 

Definition at line 244 of file cmt_string.cxx.

References allocate().

00245 {
00246   allocate (n + 1);
00247 }

int cmt_string::size  ) 
 

Definition at line 238 of file cmt_string.cxx.

References _data, and _size.

00239 {
00240   if (_data == 0) return (0);
00241   return (_size);
00242 }

int cmt_string::size  )  const
 

Definition at line 232 of file cmt_string.cxx.

References _data, and _size.

Referenced by CmtSystem::absolute_path(), Symbol::action(), ApplyPattern::action(), Tag::add(), DepsBuilder::add(), cmt_regexp::begin(), DependencyGenerator::build(), Cmt::build_makefile(), CmtSystem::cd(), Use::change_path(), cmt_char_list_node::cmt_char_list_node(), CmtSystem::compress_path(), DependencyAnalyzer::DependencyAnalyzer(), CMTPathManager::do_add_cmt_path(), Cmt::do_broadcast(), SyntaxParser::do_parse_line(), SyntaxParser::do_parse_text(), SyntaxParser::do_parse_words(), get_best_form(), CmtSystem::has_device(), CmtSystem::is_version_directory(), cmt_or_node::match(), cmt_and_node::match(), cmt_end_node::match(), cmt_one_more::match(), cmt_zero_more::match(), cmt_zero_one::match(), cmt_any_node::match(), cmt_not_char_list_node::match(), cmt_char_list_node::match(), cmt_string_node::match(), cmt_char_node::match(), ArgParser::option_tag_remove(), ArgParser::parse(), Parser::parse(), Parser::parse_line(), Cmt::parser(), Symbol::print(), Include::print_filters(), VSNETGenerator::pseudoGUID(), Use::reach_package(), read(), cmt_and_node::reduce(), ClientCollector::run(), Awk::run(), CmtSystem::scan_dir(), cmt_regexp::set(), Symbol::show_macro(), CmtSystem::split(), CmtModel::strict_expand(), trim(), Cmt::use_cmt(), Cmt::use_special_requirements(), Symbol::value_is_reflexive(), and write().

00233 {
00234   if (_data == 0) return (0);
00235   return (_size);
00236 }

void cmt_string::substr int  pos,
int  length,
cmt_string dest
const
 

Definition at line 572 of file cmt_string.cxx.

References _data, _size, and erase().

00573 {
00574   if ((_data == 0) ||
00575       (pos < 0) ||
00576       (pos >= _size))
00577     {
00578       dest = "";
00579     }
00580   else
00581     {
00582       dest = (const char*) &_data[pos];
00583       dest.erase (length);
00584     }
00585 }

void cmt_string::substr int  pos,
cmt_string dest
const
 

Definition at line 558 of file cmt_string.cxx.

References _data, and _size.

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     }
00570 }

cmt_string cmt_string::substr int  pos,
int  length
const
 

Definition at line 542 of file cmt_string.cxx.

References _data, _size, and erase().

00543 {
00544   if ((_data == 0) ||
00545       (pos < 0) ||
00546       (pos >= _size))
00547     {
00548       return ((cmt_string) "");
00549     }
00550   else
00551     {
00552       cmt_string result (&_data[pos]);
00553       result.erase (length);
00554       return (result);
00555     }
00556 }

cmt_string cmt_string::substr int  pos  )  const
 

Definition at line 528 of file cmt_string.cxx.

References _data, and _size.

Referenced by ApplyPattern::action(), Language::action(), Tag::add(), DepsBuilder::add_includes(), DependencyGenerator::add_line_to_text(), CmtSystem::basename(), ConstituentsMakefileGenerator::build(), ReadmeGenerator::build(), CmtSystem::compress_path(), Cmt::do_broadcast(), SyntaxParser::do_parse_text(), dos_script_prefix(), CmtModel::expand(), DependencyAnalyzer::filter(), TriggerAnalyzer::filter(), SequenceRunner::filter(), CmtSystem::get_dot_suffix(), CmtSystem::get_suffix(), cmt_string_node::match(), cmt_regexp::iterator::operator()(), Constituent::parse(), Parser::parse(), resolve_value(), resolve_value_for_macros(), ClientCollector::run(), Awk::run(), constituents_action_iterator::set(), Libmap::set_used(), CmtModel::strict_expand(), suppress_OS_delimiters(), and Fragment::wincopy().

00529 {
00530   if ((_data == 0) ||
00531       (pos < 0) ||
00532       (pos >= _size))
00533     {
00534       return ((cmt_string) "");
00535     }
00536   else
00537     {
00538       return ((cmt_string) &_data[pos]);
00539     }
00540 }

void cmt_string::trim  ) 
 

Definition at line 510 of file cmt_string.cxx.

References _data, _size, erase(), and size().

Referenced by DependencyAnalyzer::filter().

00511 {
00512   if (size () == 0) return;
00513 
00514   int i = 0;
00515 
00516   i = strspn (_data, " \t");
00517   if (i > 0) erase (0, i);
00518 
00519   for (i = _size - 1; i >= 0; i--)
00520     {
00521       char c = _data[i];
00522       if ((c == ' ') || (c == '\t')) continue;
00523       erase (i + 1);
00524       break;
00525     }
00526 }

void cmt_string::write ostream &  output  ) 
 

Definition at line 775 of file cmt_string.cxx.

References _data, and size().

00776 {
00777   output.write (&_data[0], size ());
00778 }

void cmt_string::write FILE *  f  )  const
 

Definition at line 770 of file cmt_string.cxx.

References _data, and size().

00771 {
00772   fwrite (&_data[0], size (), 1, f);
00773 }

bool cmt_string::write const cmt_string file_name  )  const
 

Definition at line 755 of file cmt_string.cxx.

References c_str().

Referenced by DependencyGenerator::build(), DefaultMakefileGenerator::build(), ProjectPatcher::commit(), Fragment::copy(), CvsImplementation::do_checkout_phase2(), Cmt::do_filter(), Cmt::do_set_version(), SequenceRunner::end(), SequenceRunner::filter(), install_library(), CmtLock::lock(), CvsImplementation::make_management_files(), and Fragment::wincopy().

00756 {
00757   FILE* f = fopen (file_name.c_str (), "wb");
00758   if (f != NULL)
00759     {
00760       write (f);
00761       fclose (f);
00762       return (true);
00763     }
00764   else
00765     {
00766       return (false);
00767     }
00768 }


Member Data Documentation

int cmt_string::_allocated [private]
 

Definition at line 111 of file cmt_string.h.

Referenced by allocate(), cmt_string(), and ~cmt_string().

char* cmt_string::_data [private]
 

Definition at line 110 of file cmt_string.h.

Referenced by allocate(), c_str(), cmt_string(), erase(), extend(), find(), find_last_of(), operator const char *(), operator!=(), operator+(), operator+=(), operator<(), operator=(), operator==(), operator>(), operator[](), read(), replace(), replace_all(), size(), substr(), trim(), write(), and ~cmt_string().

int cmt_string::_size [private]
 

Definition at line 112 of file cmt_string.h.

Referenced by cmt_string(), erase(), extend(), find(), operator+=(), operator=(), operator==(), operator[](), read(), replace(), replace_all(), size(), substr(), trim(), and ~cmt_string().


The documentation for this class was generated from the following files:
Generated on Mon May 2 10:25:31 2005 for CMT by doxygen 1.3.5