File tree 1 file changed +10
-11
lines changed 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -91,20 +91,19 @@ export function getQueryObject(url) {
91
91
}
92
92
93
93
/**
94
- *get getByteLen
95
- * @param {Sting } val input value
94
+ * @param {Sting } input value
96
95
* @returns {number } output value
97
96
*/
98
- export function getByteLen ( val ) {
99
- let len = 0
100
- for ( let i = 0 ; i < val . length ; i ++ ) {
101
- if ( val [ i ] . match ( / [ ^ \x00 - \xff ] / gi ) != null ) {
102
- len += 1
103
- } else {
104
- len += 0.5
105
- }
97
+ export function byteLength ( str ) {
98
+ // returns the byte length of an utf8 string
99
+ let s = str . length
100
+ for ( var i = str . length - 1 ; i >= 0 ; i -- ) {
101
+ const code = str . charCodeAt ( i )
102
+ if ( code > 0x7f && code <= 0x7ff ) s ++
103
+ else if ( code > 0x7ff && code <= 0xffff ) s += 2
104
+ if ( code >= 0xDC00 && code <= 0xDFFF ) i --
106
105
}
107
- return Math . floor ( len )
106
+ return s
108
107
}
109
108
110
109
export function cleanArray ( actual ) {
You can’t perform that action at this time.
0 commit comments