pluralmap.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. * Copyright (C) 2015, International Business Machines Corporation and
  5. * others. All Rights Reserved.
  6. */
  7. #include "unicode/unistr.h"
  8. #include "charstr.h"
  9. #include "cstring.h"
  10. #include "pluralmap.h"
  11. U_NAMESPACE_BEGIN
  12. static const char * const gPluralForms[] = {
  13. "other", "zero", "one", "two", "few", "many"};
  14. PluralMapBase::Category
  15. PluralMapBase::toCategory(const char *pluralForm) {
  16. for (int32_t i = 0; i < UPRV_LENGTHOF(gPluralForms); ++i) {
  17. if (uprv_strcmp(pluralForm, gPluralForms[i]) == 0) {
  18. return static_cast<Category>(i);
  19. }
  20. }
  21. return NONE;
  22. }
  23. PluralMapBase::Category
  24. PluralMapBase::toCategory(const UnicodeString &pluralForm) {
  25. CharString cCategory;
  26. UErrorCode status = U_ZERO_ERROR;
  27. cCategory.appendInvariantChars(pluralForm, status);
  28. return U_FAILURE(status) ? NONE : toCategory(cCategory.data());
  29. }
  30. const char *PluralMapBase::getCategoryName(Category c) {
  31. int32_t index = c;
  32. return (index < 0 || index >= UPRV_LENGTHOF(gPluralForms)) ?
  33. nullptr : gPluralForms[index];
  34. }
  35. U_NAMESPACE_END