11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
31cb0ef41Sopenharmony_ci/*
41cb0ef41Sopenharmony_ci*****************************************************************************************
51cb0ef41Sopenharmony_ci* Copyright (C) 2015, International Business Machines
61cb0ef41Sopenharmony_ci* Corporation and others. All Rights Reserved.
71cb0ef41Sopenharmony_ci*****************************************************************************************
81cb0ef41Sopenharmony_ci*/
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci#include "unicode/utypes.h"
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci#if !UCONFIG_NO_FORMATTING
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci#include "unicode/ufieldpositer.h"
151cb0ef41Sopenharmony_ci#include "unicode/fpositer.h"
161cb0ef41Sopenharmony_ci#include "unicode/localpointer.h"
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciU_NAMESPACE_USE
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ciU_CAPI UFieldPositionIterator* U_EXPORT2
221cb0ef41Sopenharmony_ciufieldpositer_open(UErrorCode* status)
231cb0ef41Sopenharmony_ci{
241cb0ef41Sopenharmony_ci    if (U_FAILURE(*status)) {
251cb0ef41Sopenharmony_ci        return nullptr;
261cb0ef41Sopenharmony_ci    }
271cb0ef41Sopenharmony_ci    FieldPositionIterator* fpositer = new FieldPositionIterator();
281cb0ef41Sopenharmony_ci    if (fpositer == nullptr) {
291cb0ef41Sopenharmony_ci        *status = U_MEMORY_ALLOCATION_ERROR;
301cb0ef41Sopenharmony_ci    }
311cb0ef41Sopenharmony_ci    return (UFieldPositionIterator*)fpositer;
321cb0ef41Sopenharmony_ci}
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
361cb0ef41Sopenharmony_ciufieldpositer_close(UFieldPositionIterator *fpositer)
371cb0ef41Sopenharmony_ci{
381cb0ef41Sopenharmony_ci    delete (FieldPositionIterator*)fpositer;
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
431cb0ef41Sopenharmony_ciufieldpositer_next(UFieldPositionIterator *fpositer,
441cb0ef41Sopenharmony_ci                   int32_t *beginIndex, int32_t *endIndex)
451cb0ef41Sopenharmony_ci{
461cb0ef41Sopenharmony_ci    FieldPosition fp;
471cb0ef41Sopenharmony_ci    int32_t field = -1;
481cb0ef41Sopenharmony_ci    if (((FieldPositionIterator*)fpositer)->next(fp)) {
491cb0ef41Sopenharmony_ci        field = fp.getField();
501cb0ef41Sopenharmony_ci        if (beginIndex) {
511cb0ef41Sopenharmony_ci            *beginIndex = fp.getBeginIndex();
521cb0ef41Sopenharmony_ci        }
531cb0ef41Sopenharmony_ci        if (endIndex) {
541cb0ef41Sopenharmony_ci            *endIndex = fp.getEndIndex();
551cb0ef41Sopenharmony_ci        }
561cb0ef41Sopenharmony_ci    }
571cb0ef41Sopenharmony_ci    return field;
581cb0ef41Sopenharmony_ci}
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci
611cb0ef41Sopenharmony_ci#endif /* #if !UCONFIG_NO_FORMATTING */
62