文字数を数えるだけ(UTF-8)

#include "hsp3utf.as" #module #defcfunc getBy […]

#include "hsp3utf.as" #module #defcfunc getBy […]

  • hk1v
  • 2021/7/5 20:54
  • タグ:
  • タグはありません
#include "hsp3utf.as"
#module
#defcfunc getByte_u8 int p1
if ((p1 >= 0x00) && (p1 <= 0x7f)) {
return 1
} else : if ((p1 >= 0xc2) && (p1 <= 0xdf)) {
return 2
} else : if ((p1 >= 0xe0) && (p1 <= 0xef)) {
return 3
} else : if ((p1 >= 0xf0) && (p1 <= 0xf7)) {
return 4
} else : if ((p1 >= 0xf8) && (p1 <= 0xfb)) {
return 5 //
} else : if ((p1 >= 0xfc) && (p1 <= 0xfd)) {
return 6 //
}
return 0
#defcfunc getCount str _txt
txt = _txt
count = 0
repeat strlen(txt)
chars = getByte_u8( peek( txt, cnt))
count++
continue cnt + chars
loop
return count
#global
//
txt = "ABCDE♨" // 11
mes txt
mes "" + getCount(txt) + ""
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX