From: Jean Privat Date: Sat, 17 Jun 2017 00:25:19 +0000 (-0400) Subject: Merge: Use prefixed chars instead of raw values X-Git-Url: http://nitlanguage.org Merge: Use prefixed chars instead of raw values The title says everything, basically all uses of `0xXXu8` in `core::text::flat` were replaced by their prefixed versions for better readability. This PR will however need c_src to be regenerated for integration. I PR this now however to make sure it is not forgotten when a c_src is later regenerated and for review purposes. Pull-Request: #2059 Reviewed-by: Jean Privat Reviewed-by: Jean-Christophe Beaupré --- 4836b6767aac991b71a6f4b8d2cec8942757d415 diff --cc lib/core/text/flat.nit index de69148,2add3d0..06cdcfe --- a/lib/core/text/flat.nit +++ b/lib/core/text/flat.nit @@@ -215,32 -208,16 +208,32 @@@ redef class FlatTex var req_esc = 0 while pos <= max do var c = its[pos] - if c == 0x0Au8 then + if c == b'\n' then req_esc += 1 - else if c == 0x09u8 then + else if c == b'\t' then req_esc += 1 - else if c == 0x22u8 then + else if c == b'"' then req_esc += 1 - else if c == 0x27u8 then + else if c == b'\'' then req_esc += 1 - else if c == 0x5Cu8 then + else if c == b'\\' then req_esc += 1 + else if c == 0x3Fu8 then + var j = pos + 1 + if j < length then + var next = its[j] + # We ignore `??'` because it will be escaped as `??\'`. + if + next == 0x21u8 or + next == 0x28u8 or + next == 0x29u8 or + next == 0x2Du8 or + next == 0x2Fu8 or + next == 0x3Cu8 or + next == 0x3Du8 or + next == 0x3Eu8 + then req_esc += 1 + end else if c < 32u8 then req_esc += 3 end @@@ -276,52 -253,31 +269,52 @@@ # * 0x22 => \" # * 0x27 => \' # * 0x5C => \\ - if c == 0x09u8 then - nns[opos] = 0x5Cu8 - nns[opos + 1] = 0x74u8 + if c == b'\t' then + nns[opos] = b'\\' + nns[opos + 1] = b't' opos += 2 - else if c == 0x0Au8 then - nns[opos] = 0x5Cu8 - nns[opos + 1] = 0x6Eu8 + else if c == b'\n' then + nns[opos] = b'\\' + nns[opos + 1] = b'n' opos += 2 - else if c == 0x22u8 then - nns[opos] = 0x5Cu8 - nns[opos + 1] = 0x22u8 + else if c == b'"' then + nns[opos] = b'\\' + nns[opos + 1] = b'"' opos += 2 - else if c == 0x27u8 then - nns[opos] = 0x5Cu8 - nns[opos + 1] = 0x27u8 + else if c == b'\'' then + nns[opos] = b'\\' + nns[opos + 1] = b'\'' opos += 2 - else if c == 0x5Cu8 then - nns[opos] = 0x5Cu8 - nns[opos + 1] = 0x5Cu8 + else if c == b'\\' then + nns[opos] = b'\\' + nns[opos + 1] = b'\\' opos += 2 + else if c == 0x3Fu8 then + var j = pos + 1 + if j < length then + var next = its[j] + # We ignore `??'` because it will be escaped as `??\'`. + if + next == 0x21u8 or + next == 0x28u8 or + next == 0x29u8 or + next == 0x2Du8 or + next == 0x2Fu8 or + next == 0x3Cu8 or + next == 0x3Du8 or + next == 0x3Eu8 + then + nns[opos] = 0x5Cu8 + opos += 1 + end + end + nns[opos] = 0x3Fu8 + opos += 1 else if c < 32u8 then - nns[opos] = 0x5Cu8 - nns[opos + 1] = 0x30u8 - nns[opos + 2] = ((c & 0x38u8) >> 3) + 0x30u8 - nns[opos + 3] = (c & 0x07u8) + 0x30u8 + nns[opos] = b'\\' + nns[opos + 1] = b'0' + nns[opos + 2] = ((c & 0x38u8) >> 3) + b'0' + nns[opos + 3] = (c & 0x07u8) + b'0' opos += 4 else nns[opos] = c