--- nono/lib/mystring.cpp 2026/04/29 17:04:28 1.1.1.1 +++ nono/lib/mystring.cpp 2026/04/29 17:04:30 1.1.1.2 @@ -5,6 +5,7 @@ #include "header.h" #include "mystring.h" +#include std::string string_format(const char *fmt, ...) @@ -21,6 +22,47 @@ string_format(const char *fmt, ...) return rv; } +// 文字列 str から先頭の連続する空白文字を取り除いた新しい文字列を返す。 +std::string +string_ltrim(const std::string& str) +{ + auto it = str.begin(); + for (; it != str.end(); it++) { + if (!isspace(*it)) + break; + } + return std::string(it, str.end()); +} + +// 文字列 str から末尾の連続する空白文字を取り除く (str を書き換える)。 +void +string_rtrim(std::string& str) +{ + while (isspace(*str.rbegin())) { + str.pop_back(); + } +} + +// 文字列 str から末尾の連続する空白文字を取り除く (str を書き換える)。 +void +rtrim(char *str) +{ + char *p = strchr(str, '\0'); + while (--p >= str && (isspace((int)*p) || *p == '\r' || *p == '\n')) { + *p = '\0'; + } +} + +// 文字列 src 中の ASCII 大文字を小文字にした新しい文字列を返す。 +std::string +string_tolower(const std::string& src) +{ + std::string dst(src); + std::transform(dst.begin(), dst.end(), dst.begin(), + [](unsigned char c){ return std::tolower(c); }); + return dst; +} + #if 0 #include #include