Same for go

Fix #2752
This commit is contained in:
Clément Fournier 2022-05-01 17:58:52 +02:00
parent 71b9362828
commit 669f2fecbd
No known key found for this signature in database
GPG Key ID: 4D8D42402E4F47E2
4 changed files with 119 additions and 4 deletions

View File

@ -1264,11 +1264,10 @@ fragment UNICODE_LETTER
| [\u31A0-\u31B7]
| [\u3400]
| [\u4DB5]
| [\u4E00]
| [\u9FA5]
| [\u4E00-\u9EA5]
| [\uA000-\uA48C]
| [\uAC00]
| [\uD7A3]
| [\uA490-\uABFF]
| [\uAC00-\uD7AF]
| [\uF900-\uFA2D]
| [\uFB00-\uFB06]
| [\uFB13-\uFB17]

View File

@ -40,4 +40,11 @@ public class GoTokenizerTest extends CpdTextComparisonTest {
public void testIssue1751() {
doTest("issue-1751");
}
@Test
public void testUnicode() {
// https://github.com/pmd/pmd/issues/2752
doTest("sample_unicode");
}
}

View File

@ -0,0 +1,20 @@
func main() {
//string底层是一个byte数组因此string也可以进行切片操作
str := "hello world"//string是不可变的
slice := str[4:]
fmt.Println(slice)
//若要对string进行修改需要将string修改为byte或rune的切片在操作
//但是转为byte无法进行中文操作
bytes := []byte(str)
bytes[2] = 'x'
str = string(bytes)
fmt.Println(str)
//转换成rune可以对中文进行操作
runes := []rune(str)
runes[0] = '哈'
str = string(runes)
fmt.Println(str)
}

View File

@ -0,0 +1,89 @@
[Image] or [Truncated image[ Bcol Ecol
L1
[func] 1 4
[main] 6 9
[(] 10 10
[)] 11 11
[{] 13 13
L3
[str] 2 4
[:=] 6 7
["hello world"] 9 21
L4
[slice] 2 6
[:=] 8 9
[str] 11 13
[\[] 14 14
[4] 15 15
[:] 16 16
[\]] 17 17
L5
[fmt] 2 4
[.] 5 5
[Println] 6 12
[(] 13 13
[slice] 14 18
[)] 19 19
L9
[bytes] 2 6
[:=] 8 9
[\[] 11 11
[\]] 12 12
[byte] 13 16
[(] 17 17
[str] 18 20
[)] 21 21
L10
[bytes] 2 6
[\[] 7 7
[2] 8 8
[\]] 9 9
[=] 11 11
['x'] 13 15
L11
[str] 2 4
[=] 6 6
[string] 8 13
[(] 14 14
[bytes] 15 19
[)] 20 20
L12
[fmt] 2 4
[.] 5 5
[Println] 6 12
[(] 13 13
[str] 14 16
[)] 17 17
L15
[runes] 2 6
[:=] 8 9
[\[] 11 11
[\]] 12 12
[rune] 13 16
[(] 17 17
[str] 18 20
[)] 21 21
L16
[runes] 2 6
[\[] 7 7
[0] 8 8
[\]] 9 9
[=] 11 11
['哈'] 13 15
L17
[str] 2 4
[=] 6 6
[string] 8 13
[(] 14 14
[runes] 15 19
[)] 20 20
L18
[fmt] 2 4
[.] 5 5
[Println] 6 12
[(] 13 13
[str] 14 16
[)] 17 17
L20
[}] 1 1
EOF