45#include "io/SectionParser.hpp"
47#include "utils/Trim.hpp"
51 void SectionParser::parse(std::istream& input, ForceField& ff,
int lineNo) {
52 const int bufferSize = 65535;
53 char buffer[bufferSize];
54 std::string line, filteredLine;
55 while (input.getline(buffer, bufferSize)) {
57 line = Utils::trimLeftCopy(buffer);
60 if (isEndSection(line)) {
62 }
else if (line.empty() ||
63 (line.size() >= 2 && line[0] ==
'/' && line[1] ==
'/') ||
64 (line.size() >= 1 && line[0] ==
'#') ||
65 (line.size() >= 1 && line[0] ==
'!')) {
68 filteredLine = stripComments(line);
69 parseLine(ff, filteredLine, lineNo);
74 std::string SectionParser::stripComments(
const std::string& line) {
75 unsigned int n = line.length();
84 for (
unsigned int i = 0; i < n; i++) {
86 if (s_cmt ==
true && line[i] ==
'\n') s_cmt =
false;
89 else if (m_cmt ==
true && line[i] ==
'*' && line[i + 1] ==
'/')
93 else if (s_cmt || m_cmt)
97 else if ((line[i] ==
'/' && line[i + 1] ==
'/') || (line[i] ==
'#'))
99 else if (line[i] ==
'/' && line[i + 1] ==
'*')
109 bool SectionParser::isEndSection(
const std::string& line) {
110 StringTokenizer tokenizer(line);
112 if (tokenizer.countTokens() >= 2) {
113 std::string keyword = tokenizer.nextToken();
115 if (keyword !=
"end") {
return false; }
117 std::string section = tokenizer.nextToken();
118 if (section == sectionName_) {
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.