http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45399

--- Comment #5 from Kay Hayen <kayhayen at gmx dot de> 2010-11-08 17:43:23 UTC 
---
(In reply to comment #4)
> The motivating examples in the original raw strings proposal are for
> simplifying regular expressions and HTML markup, there's no mention of binary
> blobs.
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2053.html

I tend to agree that avoiding of backslashes is already something. But raw
strings are definitely also useful to store arbitrary data.

I use them in Nuitka to store the binary blobs from marshaled constants.
Currently I have to have Python code like this to do that:

    def _encodeString( self, value ):
        delimiter = self._pickRawDelimiter( value )

        start = 'R"' + delimiter + "("
        end = ")" + delimiter + '"'

        result = start + value + end

        # Replace \n, \r and \0 in the raw strings. The \0 gives a silly
warning from
        # gcc (bug reported) and \n and \r even lead to wrong strings. Somehow
the
        # parser of the C++ doesn't yet play nice with these.

        def decide( match ):
            if match.group(0) == "\n":
                return end + r' "\n" ' + start
            elif match.group(0) == "\r":
                return end + r' "\r" ' + start
            else:
                return end + r' "\0" ' + start

        result = re.sub( "\n|\r|" + chr(0), decide, result )

As you can see, I somehow believe that "\n" and "\r" are not interpreted
correctly and replace these (should it be necessary, at least at one time it
was?) and then added the same for chr(0) later on.

I consider the necessity to do each of those a bug. In my mind all it should
take would be a delimiter not present in the string. Still I am thankful for
raw strings as those are way easier to get right than a readable Python to
plain C++ string translation.

And the intention of a C++ feature, since when did it ever come to limit its
use? I admit that files with "\0" inside are not the sane thing to write. But
for me C++ is something I generate as a temporary intermediate step. Please
provide a means to disable that warning without disabling everything, or even
stop it for raw strings.

Yours,
Kay

PS: If you are interested in what I do with Nuitka, feel free to visit
http://kayhayen24x7.homelinux.org/blog/nuitka-a-python-compiler/what-is-nuitka/

Reply via email to