User forums > General (but related to Code::Blocks)

Problem with '%' in editor abbreviations

<< < (4/5) > >>

thomas:
Well, I implemented it a few weeks ago... replaced '$$' with '\b' before doing variable expansion, and replaced '\b' with '$' after variable expansion.
It did not work, and that was because the same string was being expanded again.
One could leave the "special char" as it is, or one could substitute back to the escape sequence. That would work, but then client code would have to manually strip each string as the last thing, which is not good (error-prone).

mandrav:

--- Quote from: thomas on November 14, 2006, 06:54:06 pm ---Well, I implemented it a few weeks ago... replaced '$$' with '\b' before doing variable expansion, and replaced '\b' with '$' after variable expansion.
It did not work, and that was because the same string was being expanded again.
One could leave the "special char" as it is, or one could substitute back to the escape sequence. That would work, but then client code would have to manually strip each string as the last thing, which is not good (error-prone).

--- End quote ---

What 's wrong with the standard escape char '\' ?
The easiest thing to do is to add this escape char in the regular expressions: just put something like [^\\]* at the start of each regex and there you go. Am I missing something?

thomas:
It doesn't matter what you use. If you add '\' as escape char, you will have to remove it in the end, as you don't want it to appear in the final output.

mandrav:

--- Quote from: thomas on November 14, 2006, 08:24:57 pm ---It doesn't matter what you use. If you add '\' as escape char, you will have to remove it in the end, as you don't want it to appear in the final output.

--- End quote ---

Right, but *in the end*. Right before the result is returned, a replace runs and changes \$ to $ (and \% to %). What's so complicated about that?

dmoore:

--- Quote from: mandrav on November 14, 2006, 07:57:13 pm ---What 's wrong with the standard escape char '\' ?
The easiest thing to do is to add this escape char in the regular expressions: just put something like [^\\]* at the start of each regex and there you go. Am I missing something?

--- End quote ---

The problem with \ as an escape char is that if it is used for windows paths and c/c++ string literals. e.g. "This is the path to a source file in the root folder \\\\$PROJECT_FILE"

Backslash could be offered as a standard escape character (with a corresponding pre-compiled regex if speed is a concern), but there should be a way to specify an alternative escape string for some purposes.


--- Quote from: mandrav ---What's so complicated about that?

--- End quote ---

i think the complication is this:


--- Quote from: thomas ---1. the same string gets passed to MacrosManger several times during build (not during abbrevations, though). This could be considered a bug (at the very least, it is unnecessary),

--- End quote ---

until this is fixed, one could make not handling escapes the default behavior of the macro manager variable replace function (by adding optional argument for an escape string whose default value is an empty string)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version