mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-17 03:50:03 +02:00
src/utils.h: adding rtrim,ltrim,trim functions.
This commit is contained in:
parent
c5ebd757fa
commit
bab45d8a5d
2 changed files with 25 additions and 0 deletions
|
|
@ -21,6 +21,8 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include "utils.h"
|
||||
|
||||
std::vector<std::string> strsplit(const std::string& str, const std::string& delim) {
|
||||
|
|
@ -41,3 +43,22 @@ void strtolower(std::string& str) {
|
|||
|
||||
std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){ return std::tolower(c); });
|
||||
}
|
||||
|
||||
std::string& ltrim(std::string& str)
|
||||
{
|
||||
auto it = std::find_if(str.begin(), str.end(), [](char ch){ return !std::isspace(ch); });
|
||||
str.erase(str.begin(), it);
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string& rtrim(std::string& str)
|
||||
{
|
||||
auto it = std::find_if(str.rbegin(), str.rend(), [](char ch){ return !std::isspace(ch); });
|
||||
str.erase(it.base(), str.end());
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
std::string& trim(std::string& str) {
|
||||
return ltrim(rtrim(str));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue