Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 19E042PIM_T3_2020_0639
stringUtils.cpp
00001 00002 00003 #include "stringUtils.h" 00004 00005 using namespace std; 00006 00007 string trim(const string& src, const string& c) 00008 { 00009 int p2 = src.find_last_not_of(c); 00010 if (p2 == string::npos) 00011 { 00012 return string(); 00013 } 00014 00015 int p1 = src.find_first_not_of(c); 00016 if (p1 == string::npos) 00017 { 00018 p1 = 0; 00019 } 00020 00021 return src.substr(p1, (p2-p1)+1); 00022 } 00023 00024 vector<string> tokenize(const string& str, const string& delimiters) 00025 { 00026 vector<string> tokens; 00027 00028 // Skip delimiters at beginning. 00029 string::size_type lastPos = str.find_first_not_of(delimiters, 0); 00030 // Find first "non-delimiter". 00031 string::size_type pos = str.find_first_of(delimiters, lastPos); 00032 00033 while (string::npos != pos || string::npos != lastPos) 00034 { 00035 // Found a token, add it to the vector. 00036 tokens.push_back(str.substr(lastPos, pos - lastPos)); 00037 // Skip delimiters. Note the "not_of" 00038 lastPos = str.find_first_not_of(delimiters, pos); 00039 // Find next "non-delimiter" 00040 pos = str.find_first_of(delimiters, lastPos); 00041 } 00042 00043 return tokens; 00044 }
Generated on Wed Jul 27 2022 18:22:14 by
