GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
DesignLab
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
12
13
namespace
designlab::string_util
14
{
15
16
std::vector<std::string>
Split
(
const
std::string&
str
,
const
std::string&
separator
)
17
{
18
std::vector<std::string>
list
;
19
const
size_t
separator_length
=
separator
.length();
20
21
if
(
separator_length
== 0)
22
{
23
list
.push_back(
str
);
24
}
25
else
26
{
27
size_t
offset
= 0;
28
29
while
(
true
)
30
{
31
const
size_t
pos
=
str
.find(
separator
,
offset
);
32
33
if
(
pos
== std::string::npos)
34
{
35
list
.push_back(
str
.substr(
offset
));
36
break
;
37
}
38
39
list
.push_back(
str
.substr(
offset
,
pos
-
offset
));
40
offset
=
pos
+
separator_length
;
41
42
if
(
offset
>=
str
.length())
43
{
44
break
;
45
}
46
}
47
}
48
49
return
list
;
50
}
51
52
}
// namespace designlab::string_util
cassert_define.h
designlab::string_util
文字列操作に関する関数を提供する名前空間.
Definition
string_util.cpp:14
designlab::string_util::Split
std::vector< std::string > Split(const std::string &str, const std::string &separator)
文字列を分割する関数.指定した文字で文字列を分割する. 分割した結果,空白が含まれる場合や文字列がない場合は,そのまま返す. 最後が区切り文字で終わる場合は,それを無視する.
Definition
string_util.cpp:16
designlab::string_util::EnumValuesToString
std::string EnumValuesToString(const std::string separator)
enum型を渡すと,その要素を列挙した文字列を返す関数.
Definition
string_util.h:75
string_util.h
構築:
1.9.8