+
+int iterateLine(string const token, regex const reg, string const & closing,
+ int fragment_pos, DepTable & head)
+{
+ smatch what;
+ string::const_iterator first = token.begin();
+ string::const_iterator end = token.end();
+ bool fragment = false;
+ string last_match;
+
+ while (regex_search(first, end, what, reg)) {
+ // if we have a dot, try to handle as file
+ if (contains(what.str(1), '.')) {
+ first = what[0].second;
+ if (what.str(2) == closing) {
+ handleFoundFile(what.str(1), head);
+ // since we had a closing bracket,
+ // do not investigate further
+ fragment = false;
+ } else
+ // if we have no closing bracket,
+ // try to handle as file nevertheless
+ fragment = !handleFoundFile(
+ what.str(1) + what.str(2), head);
+ }
+ // if we do not have a dot, check if the line has
+ // a closing bracket (else, we suspect a line break)
+ else if (what.str(2) != closing) {
+ first = what[0].second;
+ fragment = true;
+ } else {
+ // we have a closing bracket, so the content
+ // is not a file name.
+ // no need to investigate further
+ first = what[0].second;
+ fragment = false;
+ }
+ last_match = what.str(1);
+ }
+
+ // We need to consider the result from previous line iterations:
+ // We might not find a fragment here, but another one might follow
+ // E.g.: (filename.ext) <filenam
+ // Vice versa, we consider the search completed if a real match
+ // follows a potential fragment from a previous iteration.
+ // E.g. <some text we considered a fragment (filename.ext)
+ // result = -1 means we did not find a fragment!
+ int result = -1;
+ int last_match_pos = -1;
+ if (!last_match.empty() && token.find(last_match) != string::npos)
+ last_match_pos = int(token.find(last_match));
+ if (fragment) {
+ if (last_match_pos > fragment_pos)
+ result = last_match_pos;
+ else
+ result = fragment_pos;
+ } else
+ if (last_match_pos < fragment_pos)
+ result = fragment_pos;
+
+ return result;
+}
+