ufieldpositer.h 4.3 KB

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