Garbage characters in Chinese

14 views
Skip to first unread message

codex

unread,
Oct 13, 2009, 10:32:43 PM10/13/09
to scite-interest
I try to write some code in lua:

print(props["CurrentSelection"])

Then, if the seletion includes some Chinese code, the output is
Garbage characters...

How can I deal with the problem?

Thx a lot

--codex

Neil Hodgson

unread,
Oct 15, 2009, 7:20:22 AM10/15/09
to scite-i...@googlegroups.com
codex:

> I try to write some code in lua:
>
>         print(props["CurrentSelection"])
>
> Then, if the seletion includes some Chinese code, the output is
> Garbage characters...
>
> How can I deal with the problem?

Use the same code page for the output pane as the edit pane.

Neil

codex

unread,
Oct 17, 2009, 9:34:12 PM10/17/09
to scite-interest
The properties of code page are already the same.
code.page=936
output.code.page=936

and, I'd try to use
code.page=65001
output.code.page=65001

then I got correct Chinese in props["CurrentSelection"].

One more thing,I found the feature of 'Open Selected Filename '
doesn't work for Chinese(65001 or 936).

Thx for helping.

--codex

mozers

unread,
Oct 18, 2009, 5:21:29 AM10/18/09
to codex
Sunday, October 18, 2009, 5:34:12 AM, codex wrote:

> The properties of code page are already the same.
> code.page=936
> output.code.page=936
> and, I'd try to use
> code.page=65001
> output.code.page=65001
> then I got correct Chinese in props["CurrentSelection"].

command.input, $(CurrentSelection) and $(CurrentWord) always returns the text regardless of the code.page exclusively in UTF encoding.
This bug fixed in a long time SciTE-Ru http://scite-ru.googlecode.com/svn/trunk/pack/doc/SciTE-Ru_Kernel.html#SelectionErr

Must replace lines in SciTEBase.cxx
--------------------------------------------------------------
void SciTEBase::SelectionIntoProperties() {
SString currentSelection = SelectionExtend(0, false);
props.Set("CurrentSelection", currentSelection.c_str());

SString word = SelectionWord();
props.Set("CurrentWord", word.c_str());
--------------------------------------------------------------
such
--------------------------------------------------------------
void SciTEBase::SelectionIntoProperties() {
SString currentSelection = EncodeString(SelectionExtend(0, false));
props.Set("CurrentSelection", currentSelection.c_str());

SString word = EncodeString(SelectionWord());
props.Set("CurrentWord", word.c_str());
--------------------------------------------------------------

> One more thing,I found the feature of 'Open Selected Filename '
> doesn't work for Chinese(65001 or 936).

It is possible that to correct this bug to make the same change in
another place (SelectionFilename) ?

--
mozers
<http://scite.net.ru>

mozers

unread,
Oct 18, 2009, 7:56:04 AM10/18/09
to mozers
Sunday, October 18, 2009, 1:21:29 PM, mozers wrote:
codex>> One more thing,I found the feature of 'Open Selected Filename '
codex>> doesn't work for Chinese(65001 or 936).
mozers> It is possible that to correct this bug to make the same change in
mozers> another place (SelectionFilename) ?

My assumption was correct.
Must replace line in SciTEBase.cxx
--------------------------------------------------------------
SString SciTEBase::SelectionFilename() {
return SelectionExtend(&SciTEBase::isfilenamecharforsel);
}
--------------------------------------------------------------
such
--------------------------------------------------------------
SString SciTEBase::SelectionFilename() {
return EncodeString(SelectionExtend(&SciTEBase::isfilenamecharforsel));
}
--------------------------------------------------------------
Now everything works well.

--
mozers
<http://scite.net.ru>

Neil Hodgson

unread,
Oct 18, 2009, 8:13:34 AM10/18/09
to scite-i...@googlegroups.com
codex:

> The properties of code page are already the same.
>  code.page=936
>  output.code.page=936
>
> and, I'd try to use
>  code.page=65001
>  output.code.page=65001
>
> then I got correct Chinese in props["CurrentSelection"].

There is a conversion into UTF-8 caused by this code being used to
fill in the search dialogs. You can use

text, length = editor:GetSelText()
print(text)

Neil

Neil Hodgson

unread,
Oct 18, 2009, 8:16:18 AM10/18/09
to scite-i...@googlegroups.com
mozers:

> such
> --------------------------------------------------------------
> SString SciTEBase::SelectionFilename() {
>        return EncodeString(SelectionExtend(&SciTEBase::isfilenamecharforsel));
> }
> --------------------------------------------------------------
> Now everything works well.

That will only work if the document encoding is the same as the
default platform encoding.

Neil

mozers

unread,
Oct 18, 2009, 9:42:46 AM10/18/09
to Neil Hodgson
Sunday, October 18, 2009, 4:16:18 PM, Neil wrote:

> That will only work if the document encoding is the same as the
> default platform encoding.

I agree.
My patch - is not ideal. But it works in 90% of cases.
The remained 10% should think up the best decision :)

--
mozers
<http://scite.net.ru>

codex

unread,
Oct 18, 2009, 8:46:25 PM10/18/09
to scite-interest
Both idea is available, great help, thank you so mush,

--codex
Reply all
Reply to author
Forward
0 new messages