/*
* Convert a decimal to a single digit octal number
*/
-static char octify(uint i) { return (hexsym[i % 8]); }
+static char octify(uint i)
+{
+ return (hexsym[i % 8]);
+}
/*
* Convert a decimal to a single digit hex number
*/
-static char hexify(uint i) { return (hexsym[i % 16]); }
+static char hexify(uint i)
+{
+ return (hexsym[i % 16]);
+}
/*
* Convert a octal-digit into a decimal
return 0;
}
-static char force_upper(char a) { return (islower(a)) ? toupper(a) : a; }
+static char force_upper(char a)
+{
+ return (islower(a)) ? toupper(a) : a;
+}
static int angband_stricmp(concptr a, concptr b)
{
* @param s2 比較先文字列ポインタ
* @param len 比較する長さ
* @return 等しい場合は0、p1が大きい場合は-1、p2が大きい場合は1
- * @detail
+ * @details
* strncmpの後方から比較する版
*/
int strrncmp(const char *s1, const char *s2, int len)
*
* @param str 操作の対象とする文字列
* @param delim 文字列を分割する文字
+ * @param trim trueの場合、分割した文字列の両端の空白を削除する
+ * @param num 1以上の場合、事前にvectorサイズを予約しておく(速度向上)
* @return std::vector<std::string> 分割した文字列を要素とする配列
*/
-std::vector<std::string> str_split(std::string_view str, char delim)
+std::vector<std::string> str_split(std::string_view str, char delim, bool trim, int num)
{
std::vector<std::string> result;
+ if (num > 0)
+ result.reserve(num);
+
+ auto make_str = [trim](std::string_view sv) { return trim ? str_trim(sv) : std::string(sv); };
while (true) {
bool found = false;
for (size_t i = 0; i < str.size(); ++i) {
if (str[i] == delim) {
- result.emplace_back(str.substr(0, i));
+ result.push_back(make_str(str.substr(0, i)));
str.remove_prefix(i + 1);
found = true;
break;
#endif
}
if (!found) {
- result.emplace_back(std::move(str));
+ result.push_back(make_str(str));
return result;
}
}