Skip to content

Commit

Permalink
Merge pull request #40 from ccpwcn/dev
Browse files Browse the repository at this point in the history
[fix]修复代码注释错误的问题
  • Loading branch information
ccpwcn authored Dec 19, 2023
2 parents f454d76 + fdb3a3e commit 7b3312a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
8 changes: 7 additions & 1 deletion str.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ func MaskChineseName(name string) (masked string) {
}

// MaskChineseNameEx 中文姓名脱敏,可以指定左右保留字符数量
// 示例:MaskChineseNameEx("张一二", 1, 1) => "*一*" 左边1位替代、右边1位替代
//
// 示例1:MaskChineseNameEx("张一二", 1, 1) => "张*二" 左边保留1个字符、右边保留1个字符
//
// 示例2:
//
// name := "张一二"
// MaskChineseNameEx(name, 0, utf8.RuneCountInString(name)-1) => "*一二" 左边保留0个字符、右边保留所有字符少1个
func MaskChineseNameEx(name string, left, right int) (masked string) {
size := utf8.RuneCountInString(name)
if size == 0 {
Expand Down
23 changes: 22 additions & 1 deletion str_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package kgo

import "testing"
import (
"testing"
"unicode/utf8"
)

func TestClean(t *testing.T) {
resources := map[string]string{
Expand Down Expand Up @@ -169,6 +172,24 @@ func TestMaskChineseNameEx4(t *testing.T) {
}
}

func TestMaskChineseNameEx5(t *testing.T) {
name := "张一二"
excepted := "张*二"
actual := MaskChineseNameEx(name, 1, 1)
if actual != excepted {
t.Fatalf("预期 %v,实际值:%v", excepted, actual)
}
}

func TestMaskChineseNameEx6(t *testing.T) {
name := "张一二"
excepted := "*一二"
actual := MaskChineseNameEx(name, 0, utf8.RuneCountInString(name)-1)
if actual != excepted {
t.Fatalf("预期 %v,实际值:%v", excepted, actual)
}
}

func TestMaskChineseMobile(t *testing.T) {
tel := "13012345678"
excepted := "130****5678"
Expand Down

0 comments on commit 7b3312a

Please sign in to comment.