Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """ | |
| 6 A 2to3 fixer that converts all string literals to use single quotes. | |
| 7 | |
| 8 Strings that contain single quotes will not be modified. Prefixed string | |
| 9 literals will also not be modified. This affect double-quoted strings but | |
| 10 not triple-double-quote strings. | |
| 11 | |
| 12 """ | |
| 13 | |
| 14 from lib2to3.fixer_base import BaseFix | |
| 15 from lib2to3.pgen2 import token | |
| 16 | |
| 17 | |
| 18 class FixSingleQuoteStrings(BaseFix): | |
|
eseidel
2014/09/09 23:10:55
I might have just put these both in the same file
Dirk Pranke
2014/09/09 23:32:22
Unfortunately, the way lib2to3 works each of these
| |
| 19 | |
| 20 explicit = True | |
| 21 _accept_type = token.STRING | |
| 22 | |
| 23 def match(self, node): | |
| 24 res = node.value.startswith('"') and not node.value.startswith('"""') an d "'" not in node.value[1:-1] | |
| 25 return res | |
| 26 | |
| 27 def transform(self, node, results): | |
| 28 node.value = node.value.replace('"', "'") | |
| 29 node.changed() | |
| OLD | NEW |