選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

75 行
2.0 KiB

  1. // Copyright 2016 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build ignore
  5. package main
  6. // Form defines a plural form.
  7. //
  8. // Not all languages support all forms. Also, the meaning of each form varies
  9. // per language. It is important to note that the name of a form does not
  10. // necessarily correspond one-to-one with the set of numbers. For instance,
  11. // for Croation, One matches not only 1, but also 11, 21, etc.
  12. //
  13. // Each language must at least support the form "other".
  14. type Form byte
  15. const (
  16. Other Form = iota
  17. Zero
  18. One
  19. Two
  20. Few
  21. Many
  22. )
  23. var countMap = map[string]Form{
  24. "other": Other,
  25. "zero": Zero,
  26. "one": One,
  27. "two": Two,
  28. "few": Few,
  29. "many": Many,
  30. }
  31. type pluralCheck struct {
  32. // category:
  33. // 3..7: opID
  34. // 0..2: category
  35. cat byte
  36. setID byte
  37. }
  38. // opID identifies the type of operand in the plural rule, being i, n or f.
  39. // (v, w, and t are treated as filters in our implementation.)
  40. type opID byte
  41. const (
  42. opMod opID = 0x1 // is '%' used?
  43. opNotEqual opID = 0x2 // using "!=" to compare
  44. opI opID = 0 << 2 // integers after taking the absolute value
  45. opN opID = 1 << 2 // full number (must be integer)
  46. opF opID = 2 << 2 // fraction
  47. opV opID = 3 << 2 // number of visible digits
  48. opW opID = 4 << 2 // number of visible digits without trailing zeros
  49. opBretonM opID = 5 << 2 // hard-wired rule for Breton
  50. opItalian800 opID = 6 << 2 // hard-wired rule for Italian
  51. opAzerbaijan00s opID = 7 << 2 // hard-wired rule for Azerbaijan
  52. )
  53. const (
  54. // Use this plural form to indicate the next rule needs to match as well.
  55. // The last condition in the list will have the correct plural form.
  56. andNext = 0x7
  57. formMask = 0x7
  58. opShift = 3
  59. // numN indicates the maximum integer, or maximum mod value, for which we
  60. // have inclusion masks.
  61. numN = 100
  62. // The common denominator of the modulo that is taken.
  63. maxMod = 100
  64. )