make functions in header file inline

added header guard
now string utils can be used in any part of the project
This commit is contained in:
Alex Maystrenko 2022-02-05 20:47:29 +01:00
parent 12caae8fd2
commit 061cb76fc4

View File

@ -1,15 +1,17 @@
#pragma once
#include <string> #include <string>
const std::string WHITESPACE = " \n\r\t\f\v"; const std::string WHITESPACE = " \n\r\t\f\v";
std::string ltrim(const std::string s) { inline std::string ltrim(const std::string s) {
size_t begin = s.find_first_not_of(WHITESPACE); size_t begin = s.find_first_not_of(WHITESPACE);
return (begin == std::string::npos) ? "" : s.substr(begin); return (begin == std::string::npos) ? "" : s.substr(begin);
} }
std::string rtrim(const std::string s) { inline std::string rtrim(const std::string s) {
size_t end = s.find_last_not_of(WHITESPACE); size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1); return (end == std::string::npos) ? "" : s.substr(0, end + 1);
} }
std::string trim(const std::string& s) { return rtrim(ltrim(s)); } inline std::string trim(const std::string& s) { return rtrim(ltrim(s)); }