ufieldpositer.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *****************************************************************************************
  5. * Copyright (C) 2015, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. *****************************************************************************************
  8. */
  9. #include "unicode/utypes.h"
  10. #if !UCONFIG_NO_FORMATTING
  11. #include "unicode/ufieldpositer.h"
  12. #include "unicode/fpositer.h"
  13. #include "unicode/localpointer.h"
  14. U_NAMESPACE_USE
  15. U_CAPI UFieldPositionIterator* U_EXPORT2
  16. ufieldpositer_open(UErrorCode* status)
  17. {
  18. if (U_FAILURE(*status)) {
  19. return nullptr;
  20. }
  21. FieldPositionIterator* fpositer = new FieldPositionIterator();
  22. if (fpositer == nullptr) {
  23. *status = U_MEMORY_ALLOCATION_ERROR;
  24. }
  25. return (UFieldPositionIterator*)fpositer;
  26. }
  27. U_CAPI void U_EXPORT2
  28. ufieldpositer_close(UFieldPositionIterator *fpositer)
  29. {
  30. delete (FieldPositionIterator*)fpositer;
  31. }
  32. U_CAPI int32_t U_EXPORT2
  33. ufieldpositer_next(UFieldPositionIterator *fpositer,
  34. int32_t *beginIndex, int32_t *endIndex)
  35. {
  36. FieldPosition fp;
  37. int32_t field = -1;
  38. if (((FieldPositionIterator*)fpositer)->next(fp)) {
  39. field = fp.getField();
  40. if (beginIndex) {
  41. *beginIndex = fp.getBeginIndex();
  42. }
  43. if (endIndex) {
  44. *endIndex = fp.getEndIndex();
  45. }
  46. }
  47. return field;
  48. }
  49. #endif /* #if !UCONFIG_NO_FORMATTING */