SynEdit - simple "fix" proposition

Post Reply
migajek
Posts: 3
Joined: 26 Sep 2009 11:17

SynEdit - simple "fix" proposition

Post by migajek »

Hi,
I'm playing around with SynEdit and I've found an issue I had to fix in the code of SynEdit, here it is:

First. If the loaded file is invalid UTF8, UTF8Decode function returns empty string. Personally I believe it is better to provide user with wrong encoded file, than no file at all. The best solution I've found so far was to use alternative function, from Delphi Fundamentals library. It requires cUnicodeCodecs unit ( http://fundementals.sourceforge.net/unicode.html ). The changes in SynUnicode are following: in function LoadFromStream, find

Code: Select all

{$IFDEF UNICODE}
          UnicodeStrings.Text := UTF8ToUnicodeString(UTF8Str);
{$ELSE}
          UnicodeStrings.Text := UTF8Decode(UTF8Str);
          UnicodeStrings.SaveUnicode := True;
{$ENDIF}
and replace

Code: Select all

 UnicodeStrings.Text := UTF8Decode(UTF8Str)
with

Code: Select all

UnicodeStrings.Text := UTF8StringToWideString(Utf8Str);
It loads correctly so far :)
Maël
Site Admin
Posts: 1454
Joined: 12 Mar 2005 14:15

Re: SynEdit - simple "fix" proposition

Post by Maël »

I think it should stay the way it is because there are too many websites and programs that don't really care about the proper encoding, which leads to many problems as you can often see on the garbled output.

Therefore transparent fixing of a buggy text encoding is not good IMO. Better would be to detect this and propose the user to fix it. In this case you could just use your own loading function, similar to what you have now but tell the user about the buggy encoding before fixing it (he/she should be made aware of the problem).
migajek
Posts: 3
Joined: 26 Sep 2009 11:17

Re: SynEdit - simple "fix" proposition

Post by migajek »

Maël wrote:I think it should stay the way it is because there are too many websites and programs that don't really care about the proper encoding, which leads to many problems as you can often see on the garbled output.

Therefore transparent fixing of a buggy text encoding is not good IMO. Better would be to detect this and propose the user to fix it. In this case you could just use your own loading function, similar to what you have now but tell the user about the buggy encoding before fixing it (he/she should be made aware of the problem).
Ok, that sounds better than what I provided as it seems to be more flexible, but still there should be one or two more "encodings" in the enum available, like "seUndetected" or even "seWrong" (wrong should be returned if result of UTF8Decode() is empty, while input parameter [UTF8Str] was not empty). That would allow developer to take some actions, like incorporating own utilities for charset detection or asking user or so ...
What do you think about this kind of solution?

anyway, I literally hate modifying 3rd party libraries as long as it is avoidable, unless there is any chance my modification is worth commiting. Just don't like the perspetive of dealing with troubles or even losing parts of code when updating libraries or changing my environment ...
Maël
Site Admin
Posts: 1454
Joined: 12 Mar 2005 14:15

Re: SynEdit - simple "fix" proposition

Post by Maël »

You can just implement your own LoadFile that assigns to the text property. That will work even when SynEdit gets changed.
migajek
Posts: 3
Joined: 26 Sep 2009 11:17

Re: SynEdit - simple "fix" proposition

Post by migajek »

Maël wrote:You can just implement your own LoadFile that assigns to the text property. That will work even when SynEdit gets changed.
of course, but that would require me to duplicate part of your code. moreover, if your's code get updated, I need to update it as well...

anyway it's your code at least, I don't want to push too hard ;)

BTW maybe you will tell me ... is there any activity in SynEdit project? On sourceforge from time to time the owner commits something to CSV ... but nothing else...
On your website it says that UniSynedit will become "default" one, is that true?! :)
Maël
Site Admin
Posts: 1454
Joined: 12 Mar 2005 14:15

Re: SynEdit - simple "fix" proposition

Post by Maël »

There is little activity regarding SynEdit as a whole since quite some time. W.r.t. to UniSynEdit becoming the default: it was planned but the admins never actually did the final switch to make the Unicode version the official one.
Post Reply