def fnwidth(string)
left = string.length + 1
width = pos = 0
while (string[pos] && string[pos,1] != 0.chr)
if (ctrl_char(string[0,1]) || string[0,1] == RUBOUT)
width += 2
pos+=1
else
case @encoding
when 'E'
wc = string[pos,left-pos].scan(/./me)[0]
bytes = wc.length
tempwidth = wc.length
when 'S'
wc = string[pos,left-pos].scan(/./ms)[0]
bytes = wc.length
tempwidth = wc.length
when 'U'
wc = string[pos,left-pos].scan(/./mu)[0]
bytes = wc.length
tempwidth = wc.unpack('U').first >= 0x1000 ? 2 : 1
when 'X'
wc = string[pos,left-pos].force_encoding(@encoding_name)[0]
bytes = wc.bytesize
tempwidth = wc.ord >= 0x1000 ? 2 : 1
else
wc = string[pos,left-pos].scan(/./m)[0]
bytes = wc.length
tempwidth = wc.length
end
clen = bytes
pos += clen
w = tempwidth
width += (w >= 0) ? w : 1
end
end
width
end