git.delta.rocks / unique-network / refs/commits / c1ca9e858d36

difftreelog

source

tests/src/util/util.ts905 Bsourcehistory
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56export function strToUTF16(str: string): any {7  const buf: number[] = [];8  for (let i=0, strLen=str.length; i < strLen; i++) {9    buf.push(str.charCodeAt(i));10  }11  return buf;12}1314export function utf16ToStr(buf: number[]): string {15  let str = '';16  for (let i=0, strLen=buf.length; i < strLen; i++) {17    if (buf[i] != 0) str += String.fromCharCode(buf[i]);18    else break;19  }20  return str;21}2223export function hexToStr(buf: string): string {24  let str = '';25  let hexStart = buf.indexOf('0x');26  if (hexStart < 0) hexStart = 0;27  else hexStart = 2;  28  for (let i=hexStart, strLen=buf.length; i < strLen; i+=2) {29    const ch = buf[i] + buf[i+1];30    const num = parseInt(ch, 16);31    if (num != 0) str += String.fromCharCode(num);32    else break;33  }34  return str;35}