Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: NanoBytes on August 14, 2011, 01:19:02 am

Title: The Source Code Exporter Backslash Problem
Post by: NanoBytes on August 14, 2011, 01:19:02 am
Im not sure if this topic has already been dicussed here, but im new (i made the account just to tell you guys this) I was exporting the code from one of my projects in RTF format. every time it came across a backslash character it screws up (Not because of the exporter, but because of RTF format) if the \ token is unrecognized it will simply ingore it.
eg. "Hello\0 World" would become "Hello0 World"
And it gets realy messed up with other characters such as \' or \"
BUT double backslashes work fine "Hello\\0 World" becomes "Hello\0 World"
And that is how it should be displayed, but that wont work in code

The solution is simple enough though, all you have to do is put a recognized in the RTF exporter. If the current character is a backslash simply output it twice

outputRTFChar(currentChar);
if (currentChar == '\\') outputRTFChar(currentChar);
Title: Re: The Source Code Exporter Backslash Problem
Post by: MortenMacFly on August 14, 2011, 10:43:29 am
outputRTFChar(currentChar);
if (currentChar == '\\') outputRTFChar(currentChar);
This is not as simple as it sounds, have a look at RTFExporter::RTFBody(...) - the whole content is converted at once, not char-by-char. However, it's surely do-able. Can you provide a patch accordingly, please?
Title: Re: The Source Code Exporter Backslash Problem
Post by: seb_seb0 on August 14, 2011, 06:26:07 pm
I have done a small patch here.
It works with output of "Hello\0 World".

In
Code
RTFExporter::RTFBody
, there is a switch over each character from the memory buffer. I have simply added a case:
Code
      case '\\':
        {
            rtf_body += string("\\\\");
        }
        break;

I have made a test of a 2000 lines file, and it works OK for me.

Seb
Title: Re: The Source Code Exporter Backslash Problem
Post by: NanoBytes on September 05, 2011, 04:22:17 am
Hey, Im not sure how to get your patch to work with code blocks, I have no ide where to start actualy. So could one of you simply post the Exporter.dll, or you could teach me how to use the .patch that you already posted, but the later is inpreferable.
Title: Re: The Source Code Exporter Backslash Problem
Post by: MortenMacFly on September 05, 2011, 07:04:15 am
Hey, Im not sure how to get your patch to work with code blocks, I have no ide where to start actualy. So could one of you simply post the Exporter.dll, or you could teach me how to use the .patch that you already posted, but the later is inpreferable.
Wait for the net nightly. It will have this implemented.