#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 getvarsize val
mref pval, 1024 // PVAL構造体
mref stt, 64 // stat
stt = 4
repeat 4, 2
if pval.cnt = 0 : break
stt = stt * pval.cnt
loop
return
#deffunc zenkaku val, val
mref rstr, 24 : mref string, 25
strlen i, string
sample = "09AZaz" // 半角変換対象の代表
sa = 31, 31, 32 // 全角と半角のコード差(数値, 英大字, 英小字)
getvarsize rstr : size = stat // 保存先変数サイズを取得
memset rstr, , size
repeat i
wordchk string, cnt
if (stat = -1) || (type < 0) || (type > 1) {
break
} else {
strlen i, rstr
if i + stat + 1 >= size : break // オーバーフロー防止
// 対象文字が全角
if stat {
wpeek chk, string, cnt
wpoke rstr, i, chk
// 2バイト進める
continue cnt + 2
// 対象文字が半角
} else {
peek chk, string, cnt
repeat 3
// 変換対象範囲内なら変換
peek compare.0, sample, cnt * 2 + 0
peek compare.1, sample, cnt * 2 + 1
if (chk >= compare) && (chk <= compare.1) {
poke rstr, i + 0, 130
poke rstr, i + 1, chk + sa.cnt
chk = -1 // 変換したことを示すフラグ
break
}
loop
if chk ! -1 : poke rstr, i, chk
}
}
loop
return
#global
sdim data, 128, 2 // 代入先変数は大きめに確保しておくこと!
data = "ABCabc012あいうABCabc012わをんxyz890XYZXYZ890xyz"
mes "元の文字列 " + data
zenkaku data.1, data.0
mes "全角へ変換 " + data.1
stop
|