5 #include <boost/algorithm/string/classification.hpp>
6 #include <boost/algorithm/string/split.hpp>
7 #include <boost/algorithm/string/trim.hpp>
19 const std::string& line,
22 std::istringstream is(line);
37 if (s ==
"%PASS" || s ==
"<PASS>" || s ==
"PASS") {
39 }
else if (s[0] ==
'+' || s[0] ==
'-') {
49 info.
moves.push_back(move);
63 std::cerr <<
"drop illegal move in comment " << s << std::endl;
71 bool parse_move_comment)
75 if (s.substr(1,2) ==
"* ")
79 else if (s.substr(1,2) ==
"**" && parse_move_comment)
85 if (s.find(
"$START_TIME:") == 0) {
86 const std::string YYMMDD = s.substr(12,10);
88 std::vector<std::string> e;
89 boost::algorithm::split(e, YYMMDD, boost::algorithm::is_any_of(
"/"));
92 start_date = boost::gregorian::date(stoi(e[0]), stoi(e[1]), stoi(e[2]));
93 assert(!start_date.is_special());
110 std::cerr <<
"Illegal csa line " << s << std::endl;
120 if (s.find(
"%TORYO") == 0 || s.find(
"%ILLEGAL_MOVE") == 0)
123 else if (s.find(
"%SENNICHITE") == 0)
125 else if (s.find(
"%KACHI") == 0)
128 else if (s.find(
"%JISHOGI") == 0 || s.find(
"%HIKIWAKE") == 0)
130 else if (s.find(
"%+ILLEGAL_ACTION") == 0)
132 else if (s.find(
"%-ILLEGAL_ACTION") == 0)
136 throw CsaIOError(
"unknown character in csaParseLine "+s);
143 std::ifstream ifs(filename);
145 const std::string msg =
"CsaFile::CsaFile file cannot read ";
146 std::cerr << msg << filename <<
"\n";
164 read(std::istream& is)
170 while (std::getline(is, line))
174 && (line[line.size()-1] == 13))
175 line.erase(line.size()-1);
177 std::vector<std::string> elements;
178 boost::algorithm::split(elements, line, boost::algorithm::is_any_of(
","));
179 for (
auto& e: elements) {
180 boost::algorithm::trim(e);
181 boost::algorithm::trim_left(e);
186 if (*std::min_element(board_parsed.
begin(), board_parsed.
end()) ==
false)
187 throw CsaIOError(
"incomplete position description in csaParseLine");
188 assert(record.record.initial_state.isConsistent());