Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unidecode ¶
func Unidecode(s string, errors ErrorHandling, replacement ...string) (string, error)
Unidecode transliterates Unicode text into plain 7-bit ASCII. For best results you might use NFC or NFKC normalization prior to transliteration.
Examples:
unidecode.Unidecode("北京kožušček", unidecode.Ignore) // Output: Bei Jing kozuscek unidecode.Unidecode("⁐", unidecode.Strict) // Error: no replacement found for character ⁐ in position 0 unidecode.Unidecode("⁐", unidecode.Preserve) // Output: ⁐ unidecode.Unidecode("⁐", unidecode.Replace, "?") // Output: ?
Example ¶
package main import ( "fmt" "github.com/aisbergg/go-unidecode/pkg/unidecode" ) func main() { s := "北京kožušček" d, _ := unidecode.Unidecode(s, unidecode.Ignore) fmt.Println(d) }
Output: Bei Jing kozuscek
Example (ErrorPreserve) ¶
package main import ( "fmt" "github.com/aisbergg/go-unidecode/pkg/unidecode" ) func main() { s := "⁐" d, _ := unidecode.Unidecode(s, unidecode.Preserve) fmt.Println(d) }
Output: ⁐
Example (ErrorReplace) ¶
package main import ( "fmt" "github.com/aisbergg/go-unidecode/pkg/unidecode" ) func main() { s := "⁐" d, _ := unidecode.Unidecode(s, unidecode.Replace, "?") fmt.Println(d) }
Output: ?
Example (ErrorStrict) ¶
package main import ( "fmt" "github.com/aisbergg/go-unidecode/pkg/unidecode" ) func main() { s := "⁐" _, err := unidecode.Unidecode(s, unidecode.Strict) fmt.Println(err) }
Output: no replacement found for character ⁐ in position 0
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents an error that occurred during transliteration.
type ErrorHandling ¶
type ErrorHandling uint8
ErrorHandling specifies the behavior of Unidecode in case of an error.
const ( // Ignore specifies that untransliteratable characters should be ignored. Ignore ErrorHandling = iota // Strict specifies that untransliteratable characters should cause an // error. Strict // Replace specifies that untransliteratable characters should be replaced // with a given replacement value. Replace // Preserve specifies that untransliteratable characters should be // preserved. Preserve )
Click to show internal directories.
Click to hide internal directories.