Commit cfcceff6aa921c45c2a3f0fa7a486ed9f02ccc4a
1 parent
011b1d7e
Replace std::regex_search with string_view methods in QdfFixer::processLines
Showing
1 changed file
with
17 additions
and
25 deletions
qpdf/fix-qdf.cc
| ... | ... | @@ -95,22 +95,13 @@ QdfFixer::fatal(std::string const& msg) |
| 95 | 95 | void |
| 96 | 96 | QdfFixer::processLines(std::string const& input) |
| 97 | 97 | { |
| 98 | + using namespace std::literals; | |
| 99 | + | |
| 98 | 100 | static const std::regex re_n_0_obj("^(\\d+) 0 obj\n$"); |
| 99 | - static const std::regex re_xref("^xref\n$"); | |
| 100 | - static const std::regex re_stream("^stream\n$"); | |
| 101 | - static const std::regex re_endobj("^endobj\n$"); | |
| 102 | - static const std::regex re_type_objstm("/Type /ObjStm"); | |
| 103 | - static const std::regex re_type_xref("/Type /XRef"); | |
| 104 | 101 | static const std::regex re_extends("/Extends (\\d+ 0 R)"); |
| 105 | 102 | static const std::regex re_ostream_obj("^%% Object stream: object (\\d+)"); |
| 106 | - static const std::regex re_endstream("^endstream\n$"); | |
| 107 | - static const std::regex re_length_or_w("/(Length|W) "); | |
| 108 | - static const std::regex re_size("/Size "); | |
| 109 | - static const std::regex re_ignore_newline("^%QDF: ignore_newline\n$"); | |
| 110 | 103 | static const std::regex re_num("^\\d+\n$"); |
| 111 | - static const std::regex re_trailer("^trailer <<"); | |
| 112 | 104 | static const std::regex re_size_n("^ /Size \\d+\n$"); |
| 113 | - static const std::regex re_dict_end("^>>\n$"); | |
| 114 | 105 | |
| 115 | 106 | auto sv_diff = [](size_t i) { |
| 116 | 107 | return static_cast<std::string_view::difference_type>(i); |
| ... | ... | @@ -151,22 +142,22 @@ QdfFixer::processLines(std::string const& input) |
| 151 | 142 | if (matches(re_n_0_obj)) { |
| 152 | 143 | checkObjId(m[1].str()); |
| 153 | 144 | state = st_in_obj; |
| 154 | - } else if (matches(re_xref)) { | |
| 145 | + } else if (line.compare("xref\n"sv) == 0) { | |
| 155 | 146 | xref_offset = last_offset; |
| 156 | 147 | state = st_at_xref; |
| 157 | 148 | } |
| 158 | 149 | std::cout << line; |
| 159 | 150 | } else if (state == st_in_obj) { |
| 160 | 151 | std::cout << line; |
| 161 | - if (matches(re_stream)) { | |
| 152 | + if (line.compare("stream\n"sv) == 0) { | |
| 162 | 153 | state = st_in_stream; |
| 163 | 154 | stream_start = offset; |
| 164 | - } else if (matches(re_endobj)) { | |
| 155 | + } else if (line.compare("endobj\n"sv) == 0) { | |
| 165 | 156 | state = st_top; |
| 166 | - } else if (matches(re_type_objstm)) { | |
| 157 | + } else if (line.find("/Type /ObjStm"sv) != line.npos) { | |
| 167 | 158 | state = st_in_ostream_dict; |
| 168 | 159 | ostream_id = last_obj; |
| 169 | - } else if (matches(re_type_xref)) { | |
| 160 | + } else if (line.find("/Type /XRef"sv) != line.npos) { | |
| 170 | 161 | xref_offset = xref.back().getOffset(); |
| 171 | 162 | xref_f1_nbytes = 0; |
| 172 | 163 | auto t = xref_offset; |
| ... | ... | @@ -198,7 +189,7 @@ QdfFixer::processLines(std::string const& input) |
| 198 | 189 | state = st_in_xref_stream_dict; |
| 199 | 190 | } |
| 200 | 191 | } else if (state == st_in_ostream_dict) { |
| 201 | - if (matches(re_stream)) { | |
| 192 | + if (line.compare("stream\n"sv) == 0) { | |
| 202 | 193 | state = st_in_ostream_offsets; |
| 203 | 194 | } else { |
| 204 | 195 | ostream_discarded.push_back(line); |
| ... | ... | @@ -227,21 +218,22 @@ QdfFixer::processLines(std::string const& input) |
| 227 | 218 | if (matches(re_ostream_obj)) { |
| 228 | 219 | checkObjId(m[1].str()); |
| 229 | 220 | state = st_in_ostream_outer; |
| 230 | - } else if (matches(re_endstream)) { | |
| 221 | + } else if (line.compare("endstream\n"sv) == 0) { | |
| 231 | 222 | stream_length = QIntC::to_size(last_offset - stream_start); |
| 232 | 223 | writeOstream(); |
| 233 | 224 | state = st_in_obj; |
| 234 | 225 | } |
| 235 | 226 | } else if (state == st_in_xref_stream_dict) { |
| 236 | - if (matches(re_length_or_w)) { | |
| 227 | + if ((line.find("/Length"sv) != line.npos) || | |
| 228 | + (line.find("/W"sv) != line.npos)) { | |
| 237 | 229 | // already printed |
| 238 | - } else if (matches(re_size)) { | |
| 230 | + } else if (line.find("/Size"sv) != line.npos) { | |
| 239 | 231 | auto xref_size = 1 + xref.size(); |
| 240 | 232 | std::cout << " /Size " << xref_size << "\n"; |
| 241 | 233 | } else { |
| 242 | 234 | std::cout << line; |
| 243 | 235 | } |
| 244 | - if (matches(re_stream)) { | |
| 236 | + if (line.compare("stream\n"sv) == 0) { | |
| 245 | 237 | writeBinary(0, 1); |
| 246 | 238 | writeBinary(0, xref_f1_nbytes); |
| 247 | 239 | writeBinary(0, xref_f2_nbytes); |
| ... | ... | @@ -265,13 +257,13 @@ QdfFixer::processLines(std::string const& input) |
| 265 | 257 | state = st_done; |
| 266 | 258 | } |
| 267 | 259 | } else if (state == st_in_stream) { |
| 268 | - if (matches(re_endstream)) { | |
| 260 | + if (line.compare("endstream\n"sv) == 0) { | |
| 269 | 261 | stream_length = QIntC::to_size(last_offset - stream_start); |
| 270 | 262 | state = st_after_stream; |
| 271 | 263 | } |
| 272 | 264 | std::cout << line; |
| 273 | 265 | } else if (state == st_after_stream) { |
| 274 | - if (matches(re_ignore_newline)) { | |
| 266 | + if (line.compare("%QDF: ignore_newline\n"sv) == 0) { | |
| 275 | 267 | if (stream_length > 0) { |
| 276 | 268 | --stream_length; |
| 277 | 269 | } |
| ... | ... | @@ -300,7 +292,7 @@ QdfFixer::processLines(std::string const& input) |
| 300 | 292 | } |
| 301 | 293 | state = st_before_trailer; |
| 302 | 294 | } else if (state == st_before_trailer) { |
| 303 | - if (matches(re_trailer)) { | |
| 295 | + if (line.compare("trailer <<\n"sv) == 0) { | |
| 304 | 296 | std::cout << line; |
| 305 | 297 | state = st_in_trailer; |
| 306 | 298 | } |
| ... | ... | @@ -311,7 +303,7 @@ QdfFixer::processLines(std::string const& input) |
| 311 | 303 | } else { |
| 312 | 304 | std::cout << line; |
| 313 | 305 | } |
| 314 | - if (matches(re_dict_end)) { | |
| 306 | + if (line.compare(">>\n"sv) == 0) { | |
| 315 | 307 | std::cout << "startxref\n" << xref_offset << "\n%%EOF\n"; |
| 316 | 308 | state = st_done; |
| 317 | 309 | } | ... | ... |