mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-08 16:42:15 +01:00
22 lines
508 B
Go
22 lines
508 B
Go
package normalize
|
|
|
|
import (
|
|
"unicode"
|
|
|
|
"github.com/thecodingmachine/gotenberg/internal/pkg/xerror"
|
|
"golang.org/x/text/runes"
|
|
"golang.org/x/text/transform"
|
|
"golang.org/x/text/unicode/norm"
|
|
)
|
|
|
|
// String normalizes given string.
|
|
func String(str string) (string, error) {
|
|
const op string = "normalize.String"
|
|
t := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
|
|
result, _, err := transform.String(t, str)
|
|
if err != nil {
|
|
return "", xerror.New(op, err)
|
|
}
|
|
return result, nil
|
|
}
|