You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ambiguous.go 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // This file is generated by modules/charset/ambiguous/generate.go DO NOT EDIT
  2. // Copyright 2022 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package charset
  6. import (
  7. "sort"
  8. "strings"
  9. "unicode"
  10. "code.gitea.io/gitea/modules/translation"
  11. )
  12. // AmbiguousTablesForLocale provides the table of ambiguous characters for this locale.
  13. func AmbiguousTablesForLocale(locale translation.Locale) []*AmbiguousTable {
  14. key := locale.Language()
  15. var table *AmbiguousTable
  16. var ok bool
  17. for len(key) > 0 {
  18. if table, ok = AmbiguousCharacters[key]; ok {
  19. break
  20. }
  21. idx := strings.LastIndexAny(key, "-_")
  22. if idx < 0 {
  23. key = ""
  24. } else {
  25. key = key[:idx]
  26. }
  27. }
  28. if table == nil {
  29. table = AmbiguousCharacters["_default"]
  30. }
  31. return []*AmbiguousTable{
  32. table,
  33. AmbiguousCharacters["_common"],
  34. }
  35. }
  36. func isAmbiguous(r rune, confusableTo *rune, tables ...*AmbiguousTable) bool {
  37. for _, table := range tables {
  38. if !unicode.Is(table.RangeTable, r) {
  39. continue
  40. }
  41. i := sort.Search(len(table.Confusable), func(i int) bool {
  42. return table.Confusable[i] >= r
  43. })
  44. (*confusableTo) = table.With[i]
  45. return true
  46. }
  47. return false
  48. }