Merge: Use prefixed chars instead of raw values
authorJean Privat <jean@pryen.org>
Sat, 17 Jun 2017 00:25:19 +0000 (20:25 -0400)
committerJean Privat <jean@pryen.org>
Sat, 17 Jun 2017 00:25:19 +0000 (20:25 -0400)
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 <jean@pryen.org>
Reviewed-by: Jean-Christophe Beaupré <jcbrinfo.public@gmail.com>

1  2 
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
                        # * 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