Prepare a text ``line`` for copyright detection. Always convert line to ASCII.
(line)
| 4473 | |
| 4474 | |
| 4475 | def prepare_text_line(line): |
| 4476 | """ |
| 4477 | Prepare a text ``line`` for copyright detection. |
| 4478 | Always convert line to ASCII. |
| 4479 | """ |
| 4480 | if TRACE_TOK: |
| 4481 | logger_debug(' prepare_text_line: initial: ' + repr(line)) |
| 4482 | |
| 4483 | # remove some junk in man pages: \(co |
| 4484 | line = (line |
| 4485 | .replace('\\\\ co', ' ') |
| 4486 | .replace('\\ co', ' ') |
| 4487 | .replace('(co ', ' ') |
| 4488 | ) |
| 4489 | line = remove_printf_format_codes(' ', line) |
| 4490 | if TRACE_TOK: |
| 4491 | logger_debug(' prepare_text_line: after remove_printf_format_codes: ' + repr(line)) |
| 4492 | |
| 4493 | # less common comment line prefixes |
| 4494 | line = remove_weird_comment_markers(' ', line) |
| 4495 | if TRACE_TOK: |
| 4496 | logger_debug(' prepare_text_line: after remove_weird_comment_markers: ' + repr(line)) |
| 4497 | |
| 4498 | line = remove_man_comment_markers(' ', line) |
| 4499 | if TRACE_TOK: |
| 4500 | logger_debug(' prepare_text_line: after remove_man_comment_markers: ' + repr(line)) |
| 4501 | |
| 4502 | line = remove_code_comment_markers(line) |
| 4503 | if TRACE_TOK: |
| 4504 | logger_debug(' prepare_text_line: after remove_code_comment_markers: ' + repr(line)) |
| 4505 | |
| 4506 | line = (line |
| 4507 | # C and C++ style comment markers |
| 4508 | # in rst |
| 4509 | .replace('|copy|', ' (c) ') |
| 4510 | # un common pipe chars in some ascii art |
| 4511 | .replace('|', ' ') |
| 4512 | |
| 4513 | # normalize copyright signs, quotes and spacing around them |
| 4514 | .replace('"Copyright', '" Copyright') |
| 4515 | .replace('( C)', ' (c) ') |
| 4516 | .replace('(C)', ' (c) ') |
| 4517 | .replace('(c)', ' (c) ') |
| 4518 | .replace('( © )', ' (c) ') |
| 4519 | .replace('(©)', ' (c) ') |
| 4520 | .replace('(© )', ' (c) ') |
| 4521 | .replace('( ©)', ' (c) ') |
| 4522 | .replace('©', ' (c) ') |
| 4523 | # the case of \251 is tested by 'weirdencoding.h' |
| 4524 | .replace('\251', ' (c) ') |
| 4525 | .replace('©', ' (c) ') |
| 4526 | .replace('©', ' (c) ') |
| 4527 | .replace('©', ' (c) ') |
| 4528 | .replace('©', ' (c) ') |
| 4529 | .replace('©', ' (c) ') |
| 4530 | .replace('©', ' (c) ') |
| 4531 | .replace('©', ' (c) ') |
| 4532 | .replace('u00A9', ' (c) ') |