Skip to content

Commit 27108d3

Browse files
committed
Update README
1 parent e506e26 commit 27108d3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

ports/x68k/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,33 @@ MicroPython向けLチカのコードをそのままX680x0版で動かすため
292292
# ここからは割り込み許可
293293
```
294294
295+
## 日本語文字列の扱い
296+
297+
`str` クラスでの日本語文字列の扱いに対応しています。
298+
オリジナルのMicroPythonは文字列を内部的にUTF-8で扱っていますが、X680x0の文字コードはシフトJISなので、文字列の内部処理に手を入れてシフトJISのまま扱うようになっています。
299+
300+
このため、Python文字列内のエスケープシーケンス '\uXXXX' はUnicodeではなくシフトJISのコード番号を指定します。
301+
302+
`str`オブジェクトと`bytes`/`bytearray`オブジェクトでは日本語文字列を代入したときの扱いが異なります。`str`オブジェクトは多バイト文字を文字単位で扱いますが、`bytes`/`bytearray`オブジェクトではバイトの並びとして扱います。
303+
304+
```
305+
>>> a=str('日本語','') # strオブジェクトを作成
306+
>>> a
307+
'\u93fa\u967b\u8cea'
308+
>>> len(a) # 文字数は3文字
309+
3
310+
>>> print(a)
311+
日本語
312+
313+
>>> b=bytes('日本語','') # bytesオブジェクトを作成
314+
>>> b
315+
b'\x93\xfa\x96{\x8c\xea'
316+
>>> len(6) # 6バイト
317+
6
318+
>>> print(b)
319+
b'\x93\xfa\x96{\x8c\xea'
320+
```
321+
295322
## インラインアセンブラ
296323
297324
MicroPythonのインラインアセンブラ機能をサポートしています。

0 commit comments

Comments
 (0)