11b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert/*
21b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert*****************************************************************************************
31b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert* Copyright (C) 2015, International Business Machines
41b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert* Corporation and others. All Rights Reserved.
51b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert*****************************************************************************************
61b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert*/
71b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
81b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#ifndef UFIELDPOSITER_H
91b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#define UFIELDPOSITER_H
101b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
111b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#include "unicode/utypes.h"
121b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
131b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#if !UCONFIG_NO_FORMATTING
141b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#ifndef U_HIDE_DRAFT_API
151b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
161b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#include "unicode/localpointer.h"
171b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
181b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert/**
191b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * \file
201b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * \brief C API: UFieldPositionIterator for use with format APIs.
211b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *
221b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * Usage:
231b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * ufieldpositer_open creates an empty (unset) UFieldPositionIterator.
241b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * This can be passed to format functions such as {@link #udat_formatForFields},
251b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * which will set it to apply to the fields in a particular formatted string.
261b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * ufieldpositer_next can then be used to iterate over those fields,
271b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * providing for each field its type (using values that are specific to the
281b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * particular format type, such as date or number formats), as well as the
291b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * start and end positions of the field in the formatted string.
301b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * A given UFieldPositionIterator can be re-used for different format calls;
311b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * each such call resets it to apply to that format string.
321b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * ufieldpositer_close should be called to dispose of the UFieldPositionIterator
331b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * when it is no longer needed.
341b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *
351b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @see FieldPositionIterator
361b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert */
371b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
381b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert/**
391b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * Opaque UFieldPositionIterator object for use in C.
401b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @draft ICU 55
411b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert */
421b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubertstruct UFieldPositionIterator;
431b7d32f919554dda9c193b32188251337bc756f1Fredrik Rouberttypedef struct UFieldPositionIterator UFieldPositionIterator;  /**< C typedef for struct UFieldPositionIterator. @draft ICU 55 */
441b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
451b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert/**
461b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * Open a new, unset UFieldPositionIterator object.
471b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @param status
481b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          A pointer to a UErrorCode to receive any errors.
491b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @return
501b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          A pointer to an empty (unset) UFieldPositionIterator object,
511b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          or NULL if an error occurred.
521b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @draft ICU 55
531b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert */
541b7d32f919554dda9c193b32188251337bc756f1Fredrik RoubertU_DRAFT UFieldPositionIterator* U_EXPORT2
551b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubertufieldpositer_open(UErrorCode* status);
561b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
571b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert/**
581b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * Close a UFieldPositionIterator object. Once closed it may no longer be used.
591b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @param fpositer
601b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          A pointer to the UFieldPositionIterator object to close.
611b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @draft ICU 55
621b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert */
631b7d32f919554dda9c193b32188251337bc756f1Fredrik RoubertU_DRAFT void U_EXPORT2
641b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubertufieldpositer_close(UFieldPositionIterator *fpositer);
651b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
661b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
671b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#if U_SHOW_CPLUSPLUS_API
681b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
691b7d32f919554dda9c193b32188251337bc756f1Fredrik RoubertU_NAMESPACE_BEGIN
701b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
711b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert/**
721b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * \class LocalUFieldPositionIteratorPointer
731b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * "Smart pointer" class, closes a UFieldPositionIterator via ufieldpositer_close().
741b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * For most methods see the LocalPointerBase base class.
751b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *
761b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @see LocalPointerBase
771b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @see LocalPointer
781b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @draft ICU 55
791b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert */
801b7d32f919554dda9c193b32188251337bc756f1Fredrik RoubertU_DEFINE_LOCAL_OPEN_POINTER(LocalUFieldPositionIteratorPointer, UFieldPositionIterator, ufieldpositer_close);
811b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
821b7d32f919554dda9c193b32188251337bc756f1Fredrik RoubertU_NAMESPACE_END
831b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
841b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#endif
851b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
861b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert/**
871b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * Get information for the next field in the formatted string to which this
881b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * UFieldPositionIterator currently applies, or return FALSE if there are
891b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * no more fields.
901b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @param fpositer
911b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          A pointer to the UFieldPositionIterator object containing iteration
921b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          state for the format fields.
931b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @param beginIndex
941b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          A pointer to an int32_t to receive information about the start offset
951b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          of the field in the formatted string (undefined if the function
961b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          returns a negative value). May be NULL if this information is not needed.
971b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @param endIndex
981b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          A pointer to an int32_t to receive information about the end offset
991b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          of the field in the formatted string (undefined if the function
1001b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          returns a negative value). May be NULL if this information is not needed.
1011b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @return
1021b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          The field type (non-negative value), or a negative value if there are
1031b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          no more fields for which to provide information. If negative, then any
1041b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          values pointed to by beginIndex and endIndex are undefined.
1051b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *
1061b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          The values for field type depend on what type of formatter the
1071b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          UFieldPositionIterator has been set by; for a date formatter, the
1081b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          values from the UDateFormatField enum. For more information, see the
1091b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          descriptions of format functions that take a UFieldPositionIterator*
1101b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *          parameter, such as {@link #udat_formatForFields}.
1111b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert *
1121b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert * @draft ICU 55
1131b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert */
1141b7d32f919554dda9c193b32188251337bc756f1Fredrik RoubertU_DRAFT int32_t U_EXPORT2
1151b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubertufieldpositer_next(UFieldPositionIterator *fpositer,
1161b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert                   int32_t *beginIndex, int32_t *endIndex);
1171b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
1181b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#endif /* U_HIDE_DRAFT_API */
1191b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#endif /* #if !UCONFIG_NO_FORMATTING */
1201b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert
1211b7d32f919554dda9c193b32188251337bc756f1Fredrik Roubert#endif
122