Files @ c0f165783af4
Branch filter:

Location: CryptoJS/util.js

Laman
init commit
export function str2utf8(s){
	let res=[];
	let c=s.codePointAt(0);
	for(let i=0;c!==undefined;i++,c=s.codePointAt(i)){
		console.log(c);
		if(c<0x80){res.push(c);}
		else if(c<0x800){
			res.push(0b11000000|(c>>>6));
			res.push(0b10000000|(c&0b111111));
		}
		else if(c<0x10000){
			res.push(0b11100000|(c>>>12));
			res.push(0b10000000|((c>>>6)&0b111111));
			res.push(0b10000000|(c&0b111111));
		}
		else{
			res.push(0b11110000|(c>>>18));
			res.push(0b10000000|((c>>>12)&0b111111));
			res.push(0b10000000|((c>>>6)&0b111111));
			res.push(0b10000000|(c&0b111111));
		}
	}
	return res;
}

console.log(str2utf8("$").map(x=>x.toString(16)));
console.log(str2utf8("¢").map(x=>x.toString(16)));
console.log(str2utf8("€").map(x=>x.toString(16)));
console.log(str2utf8("𐍈").map(x=>x.toString(16)));