ac-library-rs icon indicating copy to clipboard operation
ac-library-rs copied to clipboard

Workaround for Japanese Windows environment

Open mizar opened this issue 3 years ago • 3 comments

  • Avoiding problems with incorrect encoding UnicodeDecodeError: 'cp932' codec can't decode byte 0x85 in position 2897: illegal multibyte sequence
  • Added option to output directly to file PowerShell converts encoding and newline characters when passing stdout

mizar avatar Sep 01 '22 19:09 mizar

example:

mkdir -p .dist
python3 expand.py -o .dist/convolution.rs convolution
python3 expand.py -o .dist/dsu.rs dsu
python3 expand.py -o .dist/fenwicktree.rs fenwicktree
python3 expand.py -o .dist/lazysegtree.rs lazysegtree
python3 expand.py -o .dist/math.rs math
python3 expand.py -o .dist/maxflow.rs maxflow
python3 expand.py -o .dist/mincostflow.rs mincostflow
python3 expand.py -o .dist/modint.rs modint
python3 expand.py -o .dist/scc.rs scc
python3 expand.py -o .dist/segtree.rs segtree
python3 expand.py -o .dist/string.rs string
python3 expand.py -o .dist/twosat.rs twosat
python3 expand.py -o .dist/all.rs --all

mizar avatar Sep 01 '22 19:09 mizar

  • Specify utf-8 encoding and no conversion for newline characters エンコーディングを utf-8, 改行文字を無変換に指定

In Python on Japanese Windows, the default preferred encoding value for text file input/output is often cp932 (shift_jis, windows-31j) instead of utf-8, which seems to be the cause of the trouble.

日本語Windows環境でのPythonでは、テキストファイル入出力時にデフォルトとなる preferred encoding の値が utf-8 ではなく cp932 (shift_jis, windows-31j) となっている事が多いのがトラブルの原因のようです。

With no encoding, source code written in utf-8 (where non-ASCII characters (such as Uɴɪᴏɴ, Fɪɴᴅ, and other) in comments) may fail to be read by cp932 (shift_jis, windows_31j). (There is also a way to specify the -X utf8 option to python3)

エンコーディング無指定だと、utf-8で書かれたソースコード ( コメント内に UɴɪᴏɴFɪɴᴅ など、非ASCII文字が使われている部分がある ) を cp932 (shift_jis, windows_31j) で読み込もうとして失敗する場合があるため、ファイル入出力に utf-8 を強制するようにしました。 (-X utf8 オプションをpython3に指定する方法もあるようです)

  • Added option to output directly to file instead of standard output. 出力を標準出力ではなく、直接ファイル出力できるようオプション追加

When running on PowerShell, the encoding and newline characters of the stdout strings are sometimes converted, which makes it troublesome to take measures when redirecting output to a file, so I added an option to allow direct file output (if you are running on the (I guess it's no problem if you run it on command prompt, not on PowerShell (version 6 or later)...) Even with PowerShell (version 6 or later), you can use pipe instead of redirect | Out-File -Encoding utf8 filepath.rs (reconverted to UTF-8 without BOM) or something like that. (but PowerShell5 seems to have only the option -Encoding UTF-8 (UTF-8 with BOM), and what to do with newline characters, etc...)

PowerShell上で実行してしまうと、標準出力された文字列のエンコーディングや改行文字が変換されてしまう事があり、ファイルにリダイレクト出力する際の対策が面倒くさくなるため、直接ファイル出力できるオプションを追加してみました (PowerShell上ではなく、コマンドプロンプト上で実行するなら問題なさそうですが…。PowerShell (バージョン6以降) でも、リダイレクトではなくパイプで | Out-File -Encoding utf8 filepath.rs (BOMなしUTF-8へ再変換)とかすれば良いのですが、PowerShell5 では -Encoding UTF-8 (BOM有りUTF-8) のオプションしかなさそうです、更に改行文字をどうするか等は…)

mizar avatar Sep 03 '22 01:09 mizar

#109

qryxip avatar Sep 11 '22 11:09 qryxip

Rebase commit to current rust-lang-ja:master.

mizar avatar Jan 22 '23 03:01 mizar