1048147e0Sopenharmony_ci/**
2048147e0Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3048147e0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4048147e0Sopenharmony_ci * you may not use this file except in compliance with the License.
5048147e0Sopenharmony_ci * You may obtain a copy of the License at
6048147e0Sopenharmony_ci *
7048147e0Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8048147e0Sopenharmony_ci *
9048147e0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10048147e0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11048147e0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12048147e0Sopenharmony_ci * See the License for the specific language governing permissions and
13048147e0Sopenharmony_ci * limitations under the License.
14048147e0Sopenharmony_ci */
15048147e0Sopenharmony_ciimport HiLog from '../utils/HiLog';
16048147e0Sopenharmony_ci
17048147e0Sopenharmony_ciconst TAG: string = 'StringUtil';
18048147e0Sopenharmony_ciconst NON_ALPHABET_REG: RegExp = /[^\x00-\x80]/g;
19048147e0Sopenharmony_ci
20048147e0Sopenharmony_ciclass StringUtil {
21048147e0Sopenharmony_ci  public countNonAlphabet(str: string): number {
22048147e0Sopenharmony_ci    let match: RegExpMatchArray | null = str.match(NON_ALPHABET_REG);
23048147e0Sopenharmony_ci    return (!match ? 0 : match.length);
24048147e0Sopenharmony_ci  }
25048147e0Sopenharmony_ci
26048147e0Sopenharmony_ci  public getOffsetForSession(page: number): number {
27048147e0Sopenharmony_ci    let offset: number = 0;
28048147e0Sopenharmony_ci    if (page < 3) {
29048147e0Sopenharmony_ci      offset = (page - 1) * 50;
30048147e0Sopenharmony_ci    } else {
31048147e0Sopenharmony_ci      offset = (page - 2) * 100 + 50;
32048147e0Sopenharmony_ci    }
33048147e0Sopenharmony_ci    return offset;
34048147e0Sopenharmony_ci  }
35048147e0Sopenharmony_ci
36048147e0Sopenharmony_ci  public getLimitForSession(page: number): number {
37048147e0Sopenharmony_ci    let limit: number = 0;
38048147e0Sopenharmony_ci    if (page == 1) {
39048147e0Sopenharmony_ci      limit = 50;
40048147e0Sopenharmony_ci    } else {
41048147e0Sopenharmony_ci      limit = 100;
42048147e0Sopenharmony_ci    }
43048147e0Sopenharmony_ci    return limit;
44048147e0Sopenharmony_ci  }
45048147e0Sopenharmony_ci
46048147e0Sopenharmony_ci  public getGroupIdsFromResultList(resultList): Array<number> {
47048147e0Sopenharmony_ci    let groupIds: Array<number> = [];
48048147e0Sopenharmony_ci    if (resultList != null) {
49048147e0Sopenharmony_ci      for (let item of resultList) {
50048147e0Sopenharmony_ci        if (item.groupId != null) {
51048147e0Sopenharmony_ci          groupIds.push(item.groupId);
52048147e0Sopenharmony_ci        }
53048147e0Sopenharmony_ci      }
54048147e0Sopenharmony_ci    }
55048147e0Sopenharmony_ci    return groupIds;
56048147e0Sopenharmony_ci  }
57048147e0Sopenharmony_ci}
58048147e0Sopenharmony_ci
59048147e0Sopenharmony_ci// Singleton
60048147e0Sopenharmony_ciexport default new StringUtil();