If the editor encounters a character which it regards as invalid for the file font encoding, it saves the file with 0 bytes.
Even if it is in a comment.
When you try to build it, the linker will complain, because the file has been saved automatically and is empty.
But in the editor window the text is still present...
Hopefully you have a recent backup.
I had this problem two times now when copying code with string constants from other source files.
Regards,
Fred
Warning: Editor kills source file, if invalid characters
-
- CodeLite Enthusiast
- Posts: 43
- Joined: Mon Jul 02, 2012 12:53 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Warning: Editor kills source file, if invalid characters
If you got a problematic character, codelite should prompt you if it fails to save the file (and it should not save it)
Quickly looking at the code, I see that there is a check to make sure that the conversion actually succeeds before attempting to save the file.
I believe that it is a bug in wxWidgets, but in any case maybe adding another check to make sure that the file length is greater than zero will help.
I suggest that you work with svn / or git locally (git is better, since you dont need to connect to a remote server)
In addition, did you try setting another locale? ( try using ISO8859-1, or UTF8)
Make sure you open a bug report with high priority
Eran
Quickly looking at the code, I see that there is a check to make sure that the conversion actually succeeds before attempting to save the file.
I believe that it is a bug in wxWidgets, but in any case maybe adding another check to make sure that the file length is greater than zero will help.
You are right having a backup is always a good idea ( I never work without source control)Fred wrote:Hopefully you have a recent backup.
I suggest that you work with svn / or git locally (git is better, since you dont need to connect to a remote server)
In addition, did you try setting another locale? ( try using ISO8859-1, or UTF8)
Make sure you open a bug report with high priority
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Enthusiast
- Posts: 43
- Joined: Mon Jul 02, 2012 12:53 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Warning: Editor kills source file, if invalid characters
Thank you for your quick reply.
If you close the editor tab then, your code is lost.
When using the Windows API you cannot use UTF-8, because the string literals in your code would be passed UTF-8 coded to the API functions, which expect ANSI rsp. UCS-2 LE.
Regards,
Fred
There is no warning or message here, it silently overwrites the source file.eranif wrote:If you got a problematic character, codelite should prompt you if it fails to save the file (and it should not save it)
Quickly looking at the code, I see that there is a check to make sure that the conversion actually succeeds before attempting to save the file.
If you close the editor tab then, your code is lost.
Yes, I think so, too.eranif wrote:I believe that it is a bug in wxWidgets, but in any case maybe adding another check to make sure that the file length is greater than zero will help.
Fred wrote:Hopefully you have a recent backup.
I fully agree.eranif wrote:You are right having a backup is always a good idea ( I never work without source control)
I suggest that you work with svn / or git locally (git is better, since you dont need to connect to a remote server)
I am working with global editor prefererences / file font encoding = ISO-8859-1.eranif wrote:In addition, did you try setting another locale? ( try using ISO8859-1, or UTF8)
When using the Windows API you cannot use UTF-8, because the string literals in your code would be passed UTF-8 coded to the API functions, which expect ANSI rsp. UCS-2 LE.
I'll do so and give a sample.eranif wrote:Make sure you open a bug report with high priority
Eran
Regards,
Fred
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Warning: Editor kills source file, if invalid characters
Changing the global editor preferences encoding only affects how codelite converts the text before saving it.Fred wrote:When using the Windows API you cannot use UTF-8, because the string literals in your code would be passed UTF-8 coded to the API functions, which expect ANSI rsp. UCS-2 LE.
The strings will be passed as ASCII unless you set L"wide string"
Eran
Make sure you have read the HOW TO POST thread
-
- CodeLite Enthusiast
- Posts: 43
- Joined: Mon Jul 02, 2012 12:53 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Warning: Editor kills source file, if invalid characters
Thank you for your reply.
With editor file font encoding set to UTF-8 this code
the message box text is Grüße!
If the encoding is set to ISO-8859-1, the output is correct.
Regards,
Fred
No, here it is passed to the Win API function as UTF-8 bytes.eranif wrote:Changing the global editor preferences encoding only affects how codelite converts the text before saving it.Fred wrote:When using the Windows API you cannot use UTF-8, because the string literals in your code would be passed UTF-8 coded to the API functions, which expect ANSI rsp. UCS-2 LE.
The strings will be passed as ASCII unless you set L"wide string"
Eran
With editor file font encoding set to UTF-8 this code
Code: Select all
MessageBoxA(hWindow, "Grüße!", "Test", MB_OK);
If the encoding is set to ISO-8859-1, the output is correct.
Regards,
Fred
-
- CodeLite Enthusiast
- Posts: 43
- Joined: Mon Jul 02, 2012 12:53 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Warning: Editor kills source file, if invalid characters
Thank you for fixing this problem so soon.
CodeLite really is one of the few well-maintained projects!
The problem was not only with German Umlauts, but also with all UTF source code files which start with a UTF-8 'BOM'.
Looks like the wxWidgets editor cannot process this correctly
The other item, that I have to use ISO-8859-1 to have correct string literals for Win API calls, is not a problem for me.
Imo it is as expected.
For Win Unicode APIs widechars > 127 in wide literals must be escaped: const wchar_t* wStr = L"Gr\u00FC\u00DFe";
Regards,
Fred
CodeLite really is one of the few well-maintained projects!
The problem was not only with German Umlauts, but also with all UTF source code files which start with a UTF-8 'BOM'.
Looks like the wxWidgets editor cannot process this correctly
The other item, that I have to use ISO-8859-1 to have correct string literals for Win API calls, is not a problem for me.
Imo it is as expected.
For Win Unicode APIs widechars > 127 in wide literals must be escaped: const wchar_t* wStr = L"Gr\u00FC\u00DFe";
Regards,
Fred