| 120 | } |
| 121 | |
| 122 | template <class S, class C> BibTeXFile::size_type findBlock(const S & content, const BibTeXFile::size_type from, const C & startDelim, const C & endDelim, const C & escapeChar) |
| 123 | { |
| 124 | using size_type = BibTeXFile::size_type; |
| 125 | // Blocks are enclosed in {}. |
| 126 | if (content[from] != startDelim) |
| 127 | return -1; |
| 128 | |
| 129 | size_type open = 1; |
| 130 | size_type i{from + 1}; |
| 131 | bool escaped = false; |
| 132 | for (i = from + 1; i < content.size() && open > 0; ++i) { |
| 133 | if (escaped) escaped = false; |
| 134 | else if (content[i] == escapeChar) escaped = true; |
| 135 | // put endDelim check before startDelim check to ensure proper handling |
| 136 | // of startDelim == endDelim (e.g., '"') |
| 137 | else if (content[i] == endDelim) --open; |
| 138 | else if (content[i] == startDelim) ++open; |
| 139 | } |
| 140 | if (open == 0) return i - 1; |
| 141 | return -1; |
| 142 | } |
| 143 | |
| 144 | inline BibTeXFile::size_type findBlock(const QByteArray & content, const BibTeXFile::size_type from, char startDelim = '{', char endDelim = '}', char escapeChar = 0) |
| 145 | { |
no outgoing calls
no test coverage detected