ufieldpositer.h 4.4 KB

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