26 lines
534 B
Go
26 lines
534 B
Go
|
package main
|
||
|
|
||
|
import "strings"
|
||
|
|
||
|
// copied from go-junit-report for fixing issues with chars that
|
||
|
// are out of range.
|
||
|
|
||
|
// from encoding/xml/xml.go, replace chars by unknown char
|
||
|
func isInCharacterRange(r rune) (inrange bool) {
|
||
|
return r == 0x09 ||
|
||
|
r == 0x0A ||
|
||
|
r == 0x0D ||
|
||
|
r >= 0x20 && r <= 0xD7FF ||
|
||
|
r >= 0xE000 && r <= 0xFFFD ||
|
||
|
r >= 0x10000 && r <= 0x10FFFF
|
||
|
}
|
||
|
|
||
|
func escapeIllegalChars(str string) string {
|
||
|
return strings.Map(func(r rune) rune {
|
||
|
if isInCharacterRange(r) {
|
||
|
return r
|
||
|
}
|
||
|
return '\uFFFD'
|
||
|
}, str)
|
||
|
}
|