File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,33 @@ MicroPython向けLチカのコードをそのままX680x0版で動かすため
292
292
# ここからは割り込み許可
293
293
```
294
294
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
+
295
322
## インラインアセンブラ
296
323
297
324
MicroPythonのインラインアセンブラ機能をサポートしています。
You can’t perform that action at this time.
0 commit comments