• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

b1f6c1c4 / ProfessionalAccounting / 324

09 Dec 2024 01:34AM UTC coverage: 54.325% (-0.7%) from 55.047%
324

push

appveyor

b1f6c1c4
pvt prefix

6318 of 11630 relevant lines covered (54.33%)

122.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.71
/AccountingServer.BLL/Util/StringFormatter.cs
1
/* Copyright (C) 2020-2024 b1f6c1c4
2
 *
3
 * This file is part of ProfessionalAccounting.
4
 *
5
 * ProfessionalAccounting is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, version 3.
8
 *
9
 * ProfessionalAccounting is distributed in the hope that it will be useful, but
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License
12
 * for more details.
13
 *
14
 * You should have received a copy of the GNU Affero General Public License
15
 * along with ProfessionalAccounting.  If not, see
16
 * <https://www.gnu.org/licenses/>.
17
 */
18

19
using System.Text.RegularExpressions;
20

21
namespace AccountingServer.BLL.Util;
22

23
/// <summary>
24
///     字符串格式化
25
/// </summary>
26
public static class StringFormatter
27
{
28
    private static readonly Regex Reg = new(@"[\uFF00-\uFFFF\u4e00-\u9fa5¥]");
1✔
29

30
    /// <summary>
31
    ///     计算字符串长度
32
    /// </summary>
33
    /// <param name="s">字符串</param>
34
    /// <returns>长度</returns>
35
    public static int CLength(this string s)
36
    {
×
37
        s ??= string.Empty;
×
38

39
        return s.Length + Reg.Matches(s).Count;
×
40
    }
×
41

42
    /// <summary>
43
    ///     左对齐补至指定长度
44
    /// </summary>
45
    /// <param name="s">待格式化的字符串</param>
46
    /// <param name="length">长度</param>
47
    /// <param name="chr">补码</param>
48
    /// <returns>格式化的字符串</returns>
49
    public static string CPadRight(this string s, int length, char chr = ' ')
50
    {
110✔
51
        s ??= string.Empty;
110✔
52

53
        if (length - s.Length - Reg.Matches(s).Count < 0)
110✔
54
            length = s.Length + Reg.Matches(s).Count;
×
55

56
        return s + new string(chr, length - s.Length - Reg.Matches(s).Count);
110✔
57
    }
110✔
58

59

60
    /// <summary>
61
    ///     右对齐补至指定长度
62
    /// </summary>
63
    /// <param name="s">待格式化的字符串</param>
64
    /// <param name="length">长度</param>
65
    /// <param name="chr">补码</param>
66
    /// <returns>格式化的字符串</returns>
67
    public static string CPadLeft(this string s, int length, char chr = ' ')
68
    {
30✔
69
        s ??= string.Empty;
30✔
70

71
        if (length - s.Length - Reg.Matches(s).Count < 0)
30✔
72
            length = s.Length + Reg.Matches(s).Count;
×
73

74
        return new string(chr, length - s.Length - Reg.Matches(s).Count) + s;
30✔
75
    }
30✔
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc