1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { CommonUtils } from './commonUtils'; 17 18export class BundleInfoUtils { 19 /** 20 * 21 * 22 */ 23 static readonly zh: string = '阿八嚓哒妸发旮哈靃讥咔垃呣拏噢妑七呥仨它唾畖窊夕丫帀'; 24 static readonly en: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 25 26 /** 27 * 28 * 29 */ 30 static getStringZh(input: string): string { 31 let result: string = ''; 32 let upperCaseStr = input.toLocaleUpperCase(); 33 let regex: RegExp = new RegExp("[A-Z]") 34 for (let i = 0; i < input.length; i++) { 35 if (upperCaseStr[i].match(regex)) { 36 let index = upperCaseStr.charCodeAt(i) - 'A'.charCodeAt(0); 37 let ch = BundleInfoUtils.zh.charAt(index); 38 result += ch; 39 } else { 40 result += upperCaseStr[i]; 41 } 42 } 43 return result; 44 } 45 46 /** 47 * 48 * 49 */ 50 static findZhIndex(zhCharacter: string): string { 51 if (CommonUtils.isEmpty(zhCharacter) || zhCharacter.localeCompare(BundleInfoUtils.zh[0], 'zh') < 0) { 52 return '#'; 53 } 54 for (let left = 0; left < BundleInfoUtils.zh.length - 1; left++) { 55 let next = left + 1; 56 if (zhCharacter.localeCompare(BundleInfoUtils.zh[left], 'zh') >= 0 && zhCharacter.localeCompare(BundleInfoUtils.zh[next], 'zh') < 0) { 57 return BundleInfoUtils.en[left]; 58 } 59 if (next === BundleInfoUtils.zh.length - 1 && zhCharacter.localeCompare(BundleInfoUtils.zh[next], 'zh') >= 0) { 60 return BundleInfoUtils.en[next]; 61 } 62 } 63 return ''; 64 } 65 66}