utf8: deprecate utf8.char_len (#9008)
parent
f9c8d3d25c
commit
db9b523cc9
|
@ -20,7 +20,7 @@ pub enum EastAsianWidthProperty {
|
|||
pub fn display_width(s string, ambiguous_width int) int {
|
||||
mut i, mut n := 0, 0
|
||||
for i < s.len {
|
||||
c_len := utf8.char_len(s[i])
|
||||
c_len := utf8_char_len(s[i])
|
||||
n += match east_asian_width_property_at(s, i) {
|
||||
.ambiguous { ambiguous_width }
|
||||
.full, .wide { int(2) }
|
||||
|
|
|
@ -23,7 +23,7 @@ pub fn len(s string) int {
|
|||
mut index := 0
|
||||
|
||||
for {
|
||||
ch_len := char_len(s[index])
|
||||
ch_len := utf8_char_len(s[index])
|
||||
index += ch_len
|
||||
count++
|
||||
if index >= s.len {
|
||||
|
@ -39,6 +39,7 @@ pub fn u_len(s ustring) int {
|
|||
}
|
||||
|
||||
// char_len calculate the length in bytes of a utf8 char
|
||||
[deprecated: 'use builtin utf8_char_len']
|
||||
pub fn char_len(b byte) int {
|
||||
return ((0xe5000000 >> ((b >> 3) & 0x1e)) & 3) + 1
|
||||
}
|
||||
|
@ -48,7 +49,7 @@ pub fn get_uchar(s string, index int) int {
|
|||
mut res := 0
|
||||
mut ch_len := 0
|
||||
if s.len > 0 {
|
||||
ch_len = char_len(s[index])
|
||||
ch_len = utf8_char_len(s[index])
|
||||
|
||||
if ch_len == 1 {
|
||||
return u16(s[index])
|
||||
|
@ -169,7 +170,7 @@ fn up_low(s string, upper_flag bool) string {
|
|||
mut str_res := unsafe {malloc(s.len + 1)}
|
||||
|
||||
for {
|
||||
ch_len := char_len(s[index])
|
||||
ch_len := utf8_char_len(s[index])
|
||||
|
||||
if ch_len == 1 {
|
||||
if upper_flag==true {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
module scanner
|
||||
|
||||
import os
|
||||
import encoding.utf8
|
||||
import v.token
|
||||
import v.pref
|
||||
import v.util
|
||||
|
@ -1057,7 +1056,7 @@ fn (mut s Scanner) text_scan() token.Token {
|
|||
}
|
||||
|
||||
fn (mut s Scanner) invalid_character() {
|
||||
len := utf8.char_len(s.text[s.pos])
|
||||
len := utf8_char_len(s.text[s.pos])
|
||||
end := util.imin(s.pos + len, s.text.len)
|
||||
c := s.text[s.pos..end]
|
||||
s.error('invalid character `$c`')
|
||||
|
|
Loading…
Reference in New Issue