• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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*/
15let vscode = null;
16try {
17    vscode = require('vscode');
18}
19catch (err) {
20    vscode = null;
21}
22
23function print(...args) {
24    if (vscode) {
25        vscode.window.showInformationMessage(...args);
26    }
27    console.log(...args);
28}
29
30String.prototype.format = function (...args) {
31    var result = this;
32    let reg = new RegExp("%[sd]{1}")
33    for (let i = 0; i < args.length; i++) {
34        let p = result.search(reg);
35        if (p < 0) break;
36        result = result.substring(0, p) + args[i] + result.substring(p + 2, result.length);
37    }
38    return result;
39}
40
41String.prototype.replaceAll = function (...args) {
42    let result = this;
43    while (result.indexOf(args[0]) >= 0) {
44        result = result.replace(args[0], args[1]);
45    }
46    return result;
47}
48
49function replaceAll(s, sfrom, sto) {
50    while (s.indexOf(sfrom) >= 0) {
51        s = s.replace(sfrom, sto);
52    }
53    return s;
54}
55
56function getTab(tabLv) {
57    let tab = "";
58    for(var i = 0; i < tabLv; ++i) {
59        tab += "    ";
60    }
61    return tab;
62}
63
64module.exports = {
65    replaceAll,
66    print,
67    getTab
68}
69