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 */ 15import HiLog from '../utils/HiLog'; 16 17const TAG: string = 'StringUtil'; 18const NON_ALPHABET_REG: RegExp = /[^\x00-\x80]/g; 19 20class StringUtil { 21 public countNonAlphabet(str: string): number { 22 let match: RegExpMatchArray | null = str.match(NON_ALPHABET_REG); 23 return (!match ? 0 : match.length); 24 } 25 26 public getOffsetForSession(page: number): number { 27 let offset: number = 0; 28 if (page < 3) { 29 offset = (page - 1) * 50; 30 } else { 31 offset = (page - 2) * 100 + 50; 32 } 33 return offset; 34 } 35 36 public getLimitForSession(page: number): number { 37 let limit: number = 0; 38 if (page == 1) { 39 limit = 50; 40 } else { 41 limit = 100; 42 } 43 return limit; 44 } 45 46 public getGroupIdsFromResultList(resultList): Array<number> { 47 let groupIds: Array<number> = []; 48 if (resultList != null) { 49 for (let item of resultList) { 50 if (item.groupId != null) { 51 groupIds.push(item.groupId); 52 } 53 } 54 } 55 return groupIds; 56 } 57} 58 59// Singleton 60export default new StringUtil();