forked from mirrors/tar-split
common: add a UTF-8 check helper
This commit is contained in:
parent
7384cf1827
commit
2865353200
2 changed files with 55 additions and 0 deletions
21
tar/common/utf8.go
Normal file
21
tar/common/utf8.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package common
|
||||
|
||||
// IsValidUtf8String checks for in valid UTF-8 characters
|
||||
func IsValidUtf8String(s string) bool {
|
||||
for _, r := range s {
|
||||
if int(r) == 0xfffd {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// IsValidUtf8Btyes checks for in valid UTF-8 characters
|
||||
func IsValidUtf8Btyes(b []byte) bool {
|
||||
for _, r := range string(b) {
|
||||
if int(r) == 0xfffd {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue