代码拉取完成,页面将自动刷新
/* eslint-disable prefer-const */
'use strict'
const test = require('tape')
const utf8 = require('../proto/utf8')
test('UTF-8 encode', function (t) {
let utf8str = '¡hέlló wôrld!'
let count = utf8.utf8count(utf8str)
let buffer = new Uint8Array(count)
utf8.utf8encode(buffer, 0, utf8str)
let str = utf8.utf8decode(buffer, 0, buffer.length)
t.equal(str, utf8str)
t.end()
})
test('UTF-8 decode', function (t) {
let utf8str = 'ö日本語'
let utf8buf = new Uint8Array([0xC3, 0xB6, 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E])
let str = utf8.utf8decode(utf8buf, 0, utf8buf.length)
let count = utf8.utf8count(str)
let buffer = new Uint8Array(count)
utf8.utf8encode(buffer, 0, str)
t.equal(str, utf8str)
t.true(buffer.every((v, i) => v === utf8buf[i]))
t.end()
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。