string: Fix `to_cmangle` to never end with an underscore.
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Fri, 12 Dec 2014 14:55:40 +0000 (09:55 -0500)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Thu, 18 Dec 2014 13:59:28 +0000 (08:59 -0500)
This permits to use two underscores as a separator between two mangled
names (like Nitdoc does).

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

lib/standard/string.nit

index 3656e15..c4ae7b0 100644 (file)
@@ -455,10 +455,13 @@ abstract class Text
        #
        # * Contains only US-ASCII letters, digits and underscores.
        # * Never starts with a digit.
+       # * Never ends with an underscore.
        # * Never contains two contiguous underscores.
        #
        #     assert "42_is/The answer!".to_cmangle == "_52d2_is_47dThe_32danswer_33d"
+       #     assert "__".to_cmangle == "_95d_95d"
        #     assert "__d".to_cmangle == "_95d_d"
+       #     assert "_d_".to_cmangle == "_d_95d"
        #     assert "_42".to_cmangle == "_95d42"
        #     assert "foo".to_cmangle == "foo"
        #     assert "".to_cmangle == ""
@@ -500,6 +503,10 @@ abstract class Text
                                underscore = false
                        end
                end
+               if underscore then
+                       res.append('_'.ascii.to_s)
+                       res.add('d')
+               end
                return res.to_s
        end