40 void Export(
const std::string& file_path,
const T& data) {
41 const toml::basic_value<toml::preserve_comments, std::map> value(data);
42 std::string res_str = toml::format(value);
44 InsertNewLine(&res_str);
46 IndentTable(&res_str);
53 cmdio::Output(
"Failed to output TOML file. file_path : " + file_path,
58 ofs.write(res_str.c_str(), res_str.length());
62 cmdio::Output(
"TOML files are output. file_path : " + file_path,
68 void InsertNewLine(std::string* str) {
76 char past_first_char =
' ';
78 for (
const auto& s : split_str) {
79 if (s.size() != 0 && s[0] ==
'#' && past_first_char !=
'#' &&
80 past_first_char !=
' ') {
84 past_first_char = s.size() != 0 ? s[0] :
' ';
94 void IndentTable(std::string* str) {
102 bool do_indent =
false;
104 for (
size_t i = 0; i < split_str.size(); i++) {
105 std::string past_s = i != 0 ? split_str[i - 1] :
"";
106 std::string next_s = i != split_str.size() - 1 ? split_str[i + 1] :
"";
107 std::string s = split_str[i];
109 if (past_s.size() != 0 && past_s[0] ==
'[') {
113 if (next_s.size() != 0 && next_s[0] ==
'[') {
std::vector< std::string > Split(const std::string &str, const std::string &separator)
文字列を分割する関数.指定した文字で文字列を分割する. 分割した結果,空白が含まれる場合や文字列がない場合は,そのまま返す. 最後が区切り文字で終わる場合は,...