/* ---------------------------------------------------------- ファイル名 ALP_NUM_ZTOH.MAC 目的 文字列内の全角英数字を半角英数字に変換する。 入力変数 inptxt 出力変数 outtxt ------------------------------------------------------------ */ extern inptxt, outtxt; zenkaku = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789"; hankaku = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789"; outtxt = inptxt; first = 1; inplng = length(inptxt); for (inppos = 0; inppos < inplng; inppos += 1) { /* inptxt から1バイト取り出す -> ch */ ch = inptxt[inppos]; if (ch > "\000" && ch < "\200") { /* 半角文字 */ /* ch を outtxt にコピーする */ if (first) { first = 0; outtxt = ch; } else { outtxt += ch; } } else { /* 全角文字 */ if (inppos + 1 >= inplng) { /* 不都合な全角文字 */ /* ch を outtxt にコピーする */ if (first) { first = 0; outtxt = ch; } else { outtxt += ch; } } else { /* 正常な全角文字 */ /* inptxt からもう1バイト取り出す -> ch */ j2 = inppos + 1; ch = inptxt[inppos:j2]; inppos += 1; /* 全角英数字を半角英数字に変換する */ hlng = length(hankaku); for (hpos = 0; hpos < hlng; hpos += 1) { zpos1 = hpos * 2; zpos2 = zpos1 + 1; z = zenkaku[zpos1:zpos2]; h = hankaku[hpos]; n = subs(ch, z, h); if (n > 0) { /* 変換された */ break; } } /* ch を outtxt にコピー */ if (first) { first = 0; outtxt = ch; } else { outtxt += ch; } } } } /* End of file */