Changeset 12245 for trunk/FACT++/src
- Timestamp:
- 10/23/11 15:08:15 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/tools.cc
r12243 r12245 73 73 return str.substr(start, end-start+1); 74 74 } 75 76 // --------------------------------------------------------------------------77 //78 //! This is a static helper to remove leading and trailing whitespaces.79 //!80 //! Usage example:81 //!82 //! \code83 //! string str = " Dies ist ein test fuer einen ganz langen Satz "84 //! "und ob er korrekt umgebrochen und formatiert wird. Alles "85 //! "nur ein simpler test aber trotzdem ganz wichtig.";86 //!87 //! cout << setfill('-') << setw(40) << "+" << endl;88 //! while (1)89 //! {90 //! const string rc = Tools::Wrap(str, 40);91 //! if (rc.empty())92 //! break;93 //! cout << rc << endl;94 //! }95 //! \endcode96 //!97 string Tools::Wrap(string &str, size_t width)98 {99 const size_t pos = str.length()<width ? string::npos : str.find_last_of(' ', width);100 if (pos==string::npos)101 {102 const string rc = str;103 str = "";104 return rc;105 }106 107 const size_t indent = str.find_first_not_of(' ');108 109 const string rc = str.substr(0, pos);110 const size_t p2 = str.find_first_not_of(' ', pos+1);111 112 str = str.substr(0, indent) + str.substr(p2==string::npos ? pos+1 : p2);113 114 return rc;115 }
Note:
See TracChangeset
for help on using the changeset viewer.