• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *****************************************************************************************
8 */
9 
10 #include "unicode/utypes.h"
11 
12 #if !UCONFIG_NO_FORMATTING
13 
14 #include "unicode/ufieldpositer.h"
15 #include "unicode/fpositer.h"
16 #include "unicode/localpointer.h"
17 
18 U_NAMESPACE_USE
19 
20 
21 U_CAPI UFieldPositionIterator* U_EXPORT2
ufieldpositer_open(UErrorCode * status)22 ufieldpositer_open(UErrorCode* status)
23 {
24     if (U_FAILURE(*status)) {
25         return NULL;
26     }
27     FieldPositionIterator* fpositer = new FieldPositionIterator();
28     if (fpositer == NULL) {
29         *status = U_MEMORY_ALLOCATION_ERROR;
30     }
31     return (UFieldPositionIterator*)fpositer;
32 }
33 
34 
35 U_CAPI void U_EXPORT2
ufieldpositer_close(UFieldPositionIterator * fpositer)36 ufieldpositer_close(UFieldPositionIterator *fpositer)
37 {
38     delete (FieldPositionIterator*)fpositer;
39 }
40 
41 
42 U_CAPI int32_t U_EXPORT2
ufieldpositer_next(UFieldPositionIterator * fpositer,int32_t * beginIndex,int32_t * endIndex)43 ufieldpositer_next(UFieldPositionIterator *fpositer,
44                    int32_t *beginIndex, int32_t *endIndex)
45 {
46     FieldPosition fp;
47     int32_t field = -1;
48     if (((FieldPositionIterator*)fpositer)->next(fp)) {
49         field = fp.getField();
50         if (beginIndex) {
51             *beginIndex = fp.getBeginIndex();
52         }
53         if (endIndex) {
54             *endIndex = fp.getEndIndex();
55         }
56     }
57     return field;
58 }
59 
60 
61 #endif /* #if !UCONFIG_NO_FORMATTING */
62