mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
utf8: deprecate utf8.char_len (#9008)
This commit is contained in:
@ -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 {
|
||||
|
Reference in New Issue
Block a user