##// END OF EJS Templates
util: extract pure tolf/tocrlf() functions from eol extension...
Yuya Nishihara -
r31776:fe9b33bc default
parent child Browse files
Show More
@@ -113,11 +113,6 testedwith = 'ships-with-hg-core'
113
113
114 # Matches a lone LF, i.e., one that is not part of CRLF.
114 # Matches a lone LF, i.e., one that is not part of CRLF.
115 singlelf = re.compile('(^|[^\r])\n')
115 singlelf = re.compile('(^|[^\r])\n')
116 # Matches a single EOL which can either be a CRLF where repeated CR
117 # are removed or a LF. We do not care about old Macintosh files, so a
118 # stray CR is an error.
119 eolre = re.compile('\r*\n')
120
121
116
122 def inconsistenteol(data):
117 def inconsistenteol(data):
123 return '\r\n' in data and singlelf.search(data)
118 return '\r\n' in data and singlelf.search(data)
@@ -131,7 +126,7 def tolf(s, params, ui, **kwargs):
131 if (ui.configbool('eol', 'fix-trailing-newline', False)
126 if (ui.configbool('eol', 'fix-trailing-newline', False)
132 and s and s[-1] != '\n'):
127 and s and s[-1] != '\n'):
133 s = s + '\n'
128 s = s + '\n'
134 return eolre.sub('\n', s)
129 return util.tolf(s)
135
130
136 def tocrlf(s, params, ui, **kwargs):
131 def tocrlf(s, params, ui, **kwargs):
137 """Filter to convert to CRLF EOLs."""
132 """Filter to convert to CRLF EOLs."""
@@ -142,7 +137,7 def tocrlf(s, params, ui, **kwargs):
142 if (ui.configbool('eol', 'fix-trailing-newline', False)
137 if (ui.configbool('eol', 'fix-trailing-newline', False)
143 and s and s[-1] != '\n'):
138 and s and s[-1] != '\n'):
144 s = s + '\n'
139 s = s + '\n'
145 return eolre.sub('\r\n', s)
140 return util.tocrlf(s)
146
141
147 def isbinary(s, params):
142 def isbinary(s, params):
148 """Filter to do nothing with the file."""
143 """Filter to do nothing with the file."""
@@ -2200,6 +2200,17 bytecount = unitcountfn(
2200 (1, 1, _('%.0f bytes')),
2200 (1, 1, _('%.0f bytes')),
2201 )
2201 )
2202
2202
2203 # Matches a single EOL which can either be a CRLF where repeated CR
2204 # are removed or a LF. We do not care about old Macintosh files, so a
2205 # stray CR is an error.
2206 _eolre = remod.compile(br'\r*\n')
2207
2208 def tolf(s):
2209 return _eolre.sub('\n', s)
2210
2211 def tocrlf(s):
2212 return _eolre.sub('\r\n', s)
2213
2203 def escapestr(s):
2214 def escapestr(s):
2204 # call underlying function of s.encode('string_escape') directly for
2215 # call underlying function of s.encode('string_escape') directly for
2205 # Python 3 compatibility
2216 # Python 3 compatibility
General Comments 0
You need to be logged in to leave comments. Login now