1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2002-2011, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: uset_props.cpp
12 * tab size: 8 (not used)
15 * created on: 2004aug30
16 * created by: Markus W. Scherer
18 * C wrappers around UnicodeSet functions that are implemented in
19 * uniset_props.cpp, split off for modularization.
22 #include "unicode/utypes.h"
23 #include "unicode/uobject.h"
24 #include "unicode/uset.h"
25 #include "unicode/uniset.h"
27 #include "unicode/ustring.h"
28 #include "unicode/parsepos.h"
32 U_CAPI USet* U_EXPORT2
33 uset_openPattern(const UChar* pattern, int32_t patternLength,
36 UnicodeString pat(patternLength==-1, pattern, patternLength);
37 UnicodeSet* set = new UnicodeSet(pat, *ec);
40 *ec = U_MEMORY_ALLOCATION_ERROR;
51 U_CAPI USet* U_EXPORT2
52 uset_openPatternOptions(const UChar* pattern, int32_t patternLength,
56 UnicodeString pat(patternLength==-1, pattern, patternLength);
57 UnicodeSet* set = new UnicodeSet(pat, options, NULL, *ec);
60 *ec = U_MEMORY_ALLOCATION_ERROR;
72 U_CAPI int32_t U_EXPORT2
73 uset_applyPattern(USet *set,
74 const UChar *pattern, int32_t patternLength,
78 // status code needs to be checked since we
80 if(status == NULL || U_FAILURE(*status)){
84 // check only the set paramenter
85 // if pattern is NULL or null terminate
86 // UnicodeString constructor takes care of it
88 *status = U_ILLEGAL_ARGUMENT_ERROR;
92 UnicodeString pat(pattern, patternLength);
96 ((UnicodeSet*) set)->applyPattern(pat, pos, options, NULL, *status);
98 return pos.getIndex();
101 U_CAPI void U_EXPORT2
102 uset_applyIntPropertyValue(USet* set,
103 UProperty prop, int32_t value, UErrorCode* ec) {
104 ((UnicodeSet*) set)->applyIntPropertyValue(prop, value, *ec);
107 U_CAPI void U_EXPORT2
108 uset_applyPropertyAlias(USet* set,
109 const UChar *prop, int32_t propLength,
110 const UChar *value, int32_t valueLength,
113 UnicodeString p(prop, propLength);
114 UnicodeString v(value, valueLength);
116 ((UnicodeSet*) set)->applyPropertyAlias(p, v, *ec);
119 U_CAPI UBool U_EXPORT2
120 uset_resemblesPattern(const UChar *pattern, int32_t patternLength,
123 UnicodeString pat(pattern, patternLength);
125 return ((pos+1) < pat.length() &&
126 pat.charAt(pos) == (UChar)91/*[*/) ||
127 UnicodeSet::resemblesPattern(pat, pos);
130 U_CAPI int32_t U_EXPORT2
131 uset_toPattern(const USet* set,
132 UChar* result, int32_t resultCapacity,
133 UBool escapeUnprintable,
136 ((const UnicodeSet*) set)->toPattern(pat, escapeUnprintable);
137 return pat.extract(result, resultCapacity, *ec);
140 U_CAPI void U_EXPORT2
141 uset_closeOver(USet* set, int32_t attributes) {
142 ((UnicodeSet*) set)->UnicodeSet::closeOver(attributes);