Remove escape sequences; return a literal string for matching.
(have_initial_double_quote, string)
| 54 | |
| 55 | |
| 56 | def unescape_string(have_initial_double_quote, string): |
| 57 | """Remove escape sequences; return a literal string for matching.""" |
| 58 | if have_initial_double_quote: |
| 59 | tuple_ = ( |
| 60 | ('//', '/'), |
| 61 | ('\\"', '"'), |
| 62 | ('\\\\', '\\'), |
| 63 | ) |
| 64 | else: |
| 65 | tuple_ = ( |
| 66 | ('//', '\0'), |
| 67 | ('\\ ', ' '), |
| 68 | ('\\"', '"'), |
| 69 | (r"\'", "'"), |
| 70 | ('\\\\', '\\'), |
| 71 | ('\0', '/'), |
| 72 | ) |
| 73 | for from_str, to_str in tuple_: |
| 74 | string = string.replace(from_str, to_str) |
| 75 | return string |
| 76 | |
| 77 | |
| 78 | def escape_string(have_initial_double_quote, string): |