ufieldpositer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. *****************************************************************************************
  3. * Copyright (C) 2015-2016, International Business Machines
  4. * Corporation and others. All Rights Reserved.
  5. *****************************************************************************************
  6. */
  7. #ifndef UFIELDPOSITER_H
  8. #define UFIELDPOSITER_H
  9. #include "unicode/utypes.h"
  10. #if !UCONFIG_NO_FORMATTING
  11. #include "unicode/localpointer.h"
  12. /**
  13. * \file
  14. * \brief C API: UFieldPositionIterator for use with format APIs.
  15. *
  16. * Usage:
  17. * ufieldpositer_open creates an empty (unset) UFieldPositionIterator.
  18. * This can be passed to format functions such as {@link #udat_formatForFields},
  19. * which will set it to apply to the fields in a particular formatted string.
  20. * ufieldpositer_next can then be used to iterate over those fields,
  21. * providing for each field its type (using values that are specific to the
  22. * particular format type, such as date or number formats), as well as the
  23. * start and end positions of the field in the formatted string.
  24. * A given UFieldPositionIterator can be re-used for different format calls;
  25. * each such call resets it to apply to that format string.
  26. * ufieldpositer_close should be called to dispose of the UFieldPositionIterator
  27. * when it is no longer needed.
  28. *
  29. * @see FieldPositionIterator
  30. */
  31. /**
  32. * Opaque UFieldPositionIterator object for use in C.
  33. * @stable ICU 55
  34. */
  35. struct UFieldPositionIterator;
  36. typedef struct UFieldPositionIterator UFieldPositionIterator; /**< C typedef for struct UFieldPositionIterator. @stable ICU 55 */
  37. /**
  38. * Open a new, unset UFieldPositionIterator object.
  39. * @param status
  40. * A pointer to a UErrorCode to receive any errors.
  41. * @return
  42. * A pointer to an empty (unset) UFieldPositionIterator object,
  43. * or NULL if an error occurred.
  44. * @stable ICU 55
  45. */
  46. U_STABLE UFieldPositionIterator* U_EXPORT2
  47. ufieldpositer_open(UErrorCode* status);
  48. /**
  49. * Close a UFieldPositionIterator object. Once closed it may no longer be used.
  50. * @param fpositer
  51. * A pointer to the UFieldPositionIterator object to close.
  52. * @stable ICU 55
  53. */
  54. U_STABLE void U_EXPORT2
  55. ufieldpositer_close(UFieldPositionIterator *fpositer);
  56. #if U_SHOW_CPLUSPLUS_API
  57. U_NAMESPACE_BEGIN
  58. /**
  59. * \class LocalUFieldPositionIteratorPointer
  60. * "Smart pointer" class, closes a UFieldPositionIterator via ufieldpositer_close().
  61. * For most methods see the LocalPointerBase base class.
  62. *
  63. * @see LocalPointerBase
  64. * @see LocalPointer
  65. * @stable ICU 55
  66. */
  67. U_DEFINE_LOCAL_OPEN_POINTER(LocalUFieldPositionIteratorPointer, UFieldPositionIterator, ufieldpositer_close);
  68. U_NAMESPACE_END
  69. #endif
  70. /**
  71. * Get information for the next field in the formatted string to which this
  72. * UFieldPositionIterator currently applies, or return FALSE if there are
  73. * no more fields.
  74. * @param fpositer
  75. * A pointer to the UFieldPositionIterator object containing iteration
  76. * state for the format fields.
  77. * @param beginIndex
  78. * A pointer to an int32_t to receive information about the start offset
  79. * of the field in the formatted string (undefined if the function
  80. * returns a negative value). May be NULL if this information is not needed.
  81. * @param endIndex
  82. * A pointer to an int32_t to receive information about the end offset
  83. * of the field in the formatted string (undefined if the function
  84. * returns a negative value). May be NULL if this information is not needed.
  85. * @return
  86. * The field type (non-negative value), or a negative value if there are
  87. * no more fields for which to provide information. If negative, then any
  88. * values pointed to by beginIndex and endIndex are undefined.
  89. *
  90. * The values for field type depend on what type of formatter the
  91. * UFieldPositionIterator has been set by; for a date formatter, the
  92. * values from the UDateFormatField enum. For more information, see the
  93. * descriptions of format functions that take a UFieldPositionIterator*
  94. * parameter, such as {@link #udat_formatForFields}.
  95. *
  96. * @stable ICU 55
  97. */
  98. U_STABLE int32_t U_EXPORT2
  99. ufieldpositer_next(UFieldPositionIterator *fpositer,
  100. int32_t *beginIndex, int32_t *endIndex);
  101. #endif /* #if !UCONFIG_NO_FORMATTING */
  102. #endif