comparison mercurial/util.py @ 31777:6a5b69b0abec

util: add helper to convert between LF and native EOL See the next patch for why.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 29 Mar 2017 21:40:15 +0900
parents fe9b33bcec6a
children 55c0c91f55e6
comparison
equal deleted inserted replaced
31776:fe9b33bcec6a 31777:6a5b69b0abec
2208 def tolf(s): 2208 def tolf(s):
2209 return _eolre.sub('\n', s) 2209 return _eolre.sub('\n', s)
2210 2210
2211 def tocrlf(s): 2211 def tocrlf(s):
2212 return _eolre.sub('\r\n', s) 2212 return _eolre.sub('\r\n', s)
2213
2214 if pycompat.oslinesep == '\r\n':
2215 tonativeeol = tocrlf
2216 fromnativeeol = tolf
2217 else:
2218 tonativeeol = pycompat.identity
2219 fromnativeeol = pycompat.identity
2213 2220
2214 def escapestr(s): 2221 def escapestr(s):
2215 # call underlying function of s.encode('string_escape') directly for 2222 # call underlying function of s.encode('string_escape') directly for
2216 # Python 3 compatibility 2223 # Python 3 compatibility
2217 return codecs.escape_encode(s)[0] 2224 return codecs.escape_encode(s)[0]