mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-02 11:43:40 +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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
std::vector<std::string> strsplit(const std::string& str, const std::string& delim) {
|
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::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));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,8 @@ std::vector<std::string> strsplit(const std::string& str, const std::string& del
|
||||||
|
|
||||||
void strtolower(std::string& str);
|
void strtolower(std::string& str);
|
||||||
|
|
||||||
|
std::string& rtrim(std::string& str);
|
||||||
|
std::string& ltrim(std::string& str);
|
||||||
|
std::string& trim(std::string& str);
|
||||||
|
|
||||||
#endif /* UTILS_H */
|
#endif /* UTILS_H */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue