1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617export function strToUTF16(str: string): any {18 const buf: number[] = [];19 for (let i=0, strLen=str.length; i < strLen; i++) {20 buf.push(str.charCodeAt(i));21 }22 return buf;23}2425export function utf16ToStr(buf: number[]): string {26 let str = '';27 for (let i=0, strLen=buf.length; i < strLen; i++) {28 if (buf[i] != 0) str += String.fromCharCode(buf[i]);29 else break;30 }31 return str;32}3334export function hexToStr(buf: string): string {35 let str = '';36 let hexStart = buf.indexOf('0x');37 if (hexStart < 0) hexStart = 0;38 else hexStart = 2; 39 for (let i=hexStart, strLen=buf.length; i < strLen; i+=2) {40 const ch = buf[i] + buf[i+1];41 const num = parseInt(ch, 16);42 if (num != 0) str += String.fromCharCode(num);43 else break;44 }45 return str;46}difftreelog
source
tests/src/deprecated-helpers/util.ts1.5 KiBsourcehistory