GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
string_util.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#include "string_util.h"
9
10#include "cassert_define.h"
11
13
14std::vector<std::string> Split(const std::string& str,
15 const std::string& separator) {
16 std::vector<std::string> list;
17 const size_t separator_length = separator.length();
18
19 if (separator_length == 0) {
20 list.push_back(str);
21 } else {
22 size_t offset = 0;
23
24 while (true) {
25 const size_t pos = str.find(separator, offset);
26
27 if (pos == std::string::npos) {
28 list.push_back(str.substr(offset));
29 break;
30 }
31
32 list.push_back(str.substr(offset, pos - offset));
34
35 if (offset >= str.length()) {
36 break;
37 }
38 }
39 }
40
41 return list;
42}
43
44} // namespace designlab::string_util
文字列操作に関する関数を提供する名前空間.
std::vector< std::string > Split(const std::string &str, const std::string &separator)
文字列を分割する関数.指定した文字で文字列を分割する. 分割した結果,空白が含まれる場合や文字列がない場合は,そのまま返す. 最後が区切り文字で終わる場合は,...
std::string EnumValuesToString(const std::string separator)
enum型を渡すと,その要素を列挙した文字列を返す関数.
Definition string_util.h:72