Changeset 24110
- Timestamp:
- 2011-06-03T09:19:39+12:00 (13 years ago)
- Location:
- main/trunk/greenstone2/common-src/src/lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/common-src/src/lib/text_t.cpp
r22141 r24110 51 51 52 52 #include "unitool.h" 53 #include <iostream> 53 54 54 55 const text_t g_EmptyText(""); … … 711 712 } 712 713 714 //Trims the whitespace off the beginning and end of a given string 715 text_t trim (const text_t& text) { 716 717 if(text.size() == 0) { 718 return text; 719 } 720 721 text_t::const_iterator firstLetter = text.begin(); 722 text_t::const_iterator lastLetter = text.end(); 723 724 //Find the start 725 while (firstLetter != lastLetter) { 726 if(!is_unicode_space(*firstLetter)) { 727 break; 728 } 729 firstLetter++; 730 } 731 732 //Find the end 733 while (lastLetter != firstLetter) { 734 if(!is_unicode_space(*lastLetter)) { 735 break; 736 } 737 lastLetter--; 738 } 739 740 return substr(firstLetter, lastLetter+1); 741 } 713 742 714 743 //////////////////////////////////// -
main/trunk/greenstone2/common-src/src/lib/text_t.h
r22141 r24110 289 289 bool ends_with(const text_t& text, const text_t& suffix); 290 290 291 // trims whitespace of the front and end of the string 292 text_t trim(const text_t& text); 293 291 294 // conversion classes used for getting information in to and out of 292 295 // the text_t class.
Note:
See TracChangeset
for help on using the changeset viewer.