#module
#deffunc wordchk val, int
mref txt, 24 : mref ichi, 1
mref stt, 64
peek chk, txt, ichi
if chk = 0 : stt = -1 : return // 範囲外
if (chk > 128 & (chk < 160)) | (chk > 223) : stt = 1 : else : stt = 0 // 1byte=0 2byte=1
return
#deffunc bytechk val, int
mref s, 24 : mref p, 1
mref stt, 64
// 対象コードをチェックする
wordchk s, p
code = stat
if code = -1 : return // 範囲外
// 対象コードより前を確認
repeat , 1
wordchk s, p - cnt
// 全てをチェックし終わったか、1バイト文字が来た
if (stat = -1) || (stat = 0) {
if code = 0 {
// 1バイト領域になったのが奇数回なら半角、偶数回なら全角2バイト目
if cnt \ 2 = 1 : stt = 0 : else : stt = 2
} else {
// 1バイト領域になったのが奇数回なら全角1バイト目、偶数回なら全角2バイト目
if cnt \ 2 = 1 : stt = 1 : else : stt = 2
}
break
}
loop
return
#global
sdim type, 24, 3
string = "abあcdeいfうghえijおklmかnopきqくrsけtuvこwxyz"
type = "1バイト文字","2バイト文字1バイト目","2バイト文字2バイト目"
strlen len, string
randomize
font "MS 明朝", 12
color 255
pos 30, 20 : mes string
color , , 255
pos 30, 5 : mes "01234567890123456789012345678901234567890123456789"
pos 30, 50 : mes "位置"
pos 80, 50 : mes "文字"
pos 150, 50 : mes "タイプ"
color
repeat 25
rnd r, len
bytechk string, r // 適当な位置のコードをチェックする
switch stat
case 0: strmid get, string, r, 1 : swbreak
case 1: strmid get, string, r, 2 : swbreak
case 2: strmid get, string, r - 1, 2
swend
pos 30, cnt * 15 + 65 : mes r
pos 80, cnt * 15 + 65 : mes get
pos 150, cnt * 15 + 65 : mes type.stat
loop
stop
|