2 *******************************************************************************
4 * Copyright (C) 2002-2005, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: uset_props.cpp
10 * tab size: 8 (not used)
13 * created on: 2004aug30
14 * created by: Markus W. Scherer
16 * C wrappers around UnicodeSet functions that are implemented in
17 * uniset_props.cpp, split off for modularization.
20 #include "unicode/utypes.h"
21 #include "unicode/uobject.h"
22 #include "unicode/uset.h"
23 #include "unicode/uniset.h"
25 #include "unicode/ustring.h"
26 #include "unicode/parsepos.h"
28 U_CAPI USet
* U_EXPORT2
29 uset_openPattern(const UChar
* pattern
, int32_t patternLength
,
32 UnicodeString
pat(patternLength
==-1, pattern
, patternLength
);
33 UnicodeSet
* set
= new UnicodeSet(pat
, *ec
);
36 *ec
= U_MEMORY_ALLOCATION_ERROR
;
47 U_CAPI USet
* U_EXPORT2
48 uset_openPatternOptions(const UChar
* pattern
, int32_t patternLength
,
52 UnicodeString
pat(patternLength
==-1, pattern
, patternLength
);
53 UnicodeSet
* set
= new UnicodeSet(pat
, options
, NULL
, *ec
);
56 *ec
= U_MEMORY_ALLOCATION_ERROR
;
68 U_CAPI
int32_t U_EXPORT2
69 uset_applyPattern(USet
*set
,
70 const UChar
*pattern
, int32_t patternLength
,
74 // status code needs to be checked since we
76 if(status
== NULL
|| U_FAILURE(*status
)){
80 // check only the set paramenter
81 // if pattern is NULL or null terminate
82 // UnicodeString constructor takes care of it
84 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
88 UnicodeString
pat(pattern
, patternLength
);
92 ((UnicodeSet
*) set
)->applyPattern(pat
, pos
, options
, NULL
, *status
);
94 return pos
.getIndex();
98 uset_applyIntPropertyValue(USet
* set
,
99 UProperty prop
, int32_t value
, UErrorCode
* ec
) {
100 ((UnicodeSet
*) set
)->applyIntPropertyValue(prop
, value
, *ec
);
103 U_CAPI
void U_EXPORT2
104 uset_applyPropertyAlias(USet
* set
,
105 const UChar
*prop
, int32_t propLength
,
106 const UChar
*value
, int32_t valueLength
,
109 UnicodeString
p(prop
, propLength
);
110 UnicodeString
v(value
, valueLength
);
112 ((UnicodeSet
*) set
)->applyPropertyAlias(p
, v
, *ec
);
115 U_CAPI UBool U_EXPORT2
116 uset_resemblesPattern(const UChar
*pattern
, int32_t patternLength
,
119 UnicodeString
pat(pattern
, patternLength
);
121 return ((pos
+1) < pat
.length() &&
122 pat
.charAt(pos
) == (UChar
)91/*[*/) ||
123 UnicodeSet::resemblesPattern(pat
, pos
);
126 U_CAPI
int32_t U_EXPORT2
127 uset_toPattern(const USet
* set
,
128 UChar
* result
, int32_t resultCapacity
,
129 UBool escapeUnprintable
,
132 ((const UnicodeSet
*) set
)->toPattern(pat
, escapeUnprintable
);
133 return pat
.extract(result
, resultCapacity
, *ec
);