2 *******************************************************************************
4 * Copyright (C) 2002-2006, 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"
30 U_CAPI USet
* U_EXPORT2
31 uset_openPattern(const UChar
* pattern
, int32_t patternLength
,
34 UnicodeString
pat(patternLength
==-1, pattern
, patternLength
);
35 UnicodeSet
* set
= new UnicodeSet(pat
, *ec
);
38 *ec
= U_MEMORY_ALLOCATION_ERROR
;
49 U_CAPI USet
* U_EXPORT2
50 uset_openPatternOptions(const UChar
* pattern
, int32_t patternLength
,
54 UnicodeString
pat(patternLength
==-1, pattern
, patternLength
);
55 UnicodeSet
* set
= new UnicodeSet(pat
, options
, NULL
, *ec
);
58 *ec
= U_MEMORY_ALLOCATION_ERROR
;
70 U_CAPI
int32_t U_EXPORT2
71 uset_applyPattern(USet
*set
,
72 const UChar
*pattern
, int32_t patternLength
,
76 // status code needs to be checked since we
78 if(status
== NULL
|| U_FAILURE(*status
)){
82 // check only the set paramenter
83 // if pattern is NULL or null terminate
84 // UnicodeString constructor takes care of it
86 *status
= U_ILLEGAL_ARGUMENT_ERROR
;
90 UnicodeString
pat(pattern
, patternLength
);
94 ((UnicodeSet
*) set
)->applyPattern(pat
, pos
, options
, NULL
, *status
);
96 return pos
.getIndex();
100 uset_applyIntPropertyValue(USet
* set
,
101 UProperty prop
, int32_t value
, UErrorCode
* ec
) {
102 ((UnicodeSet
*) set
)->applyIntPropertyValue(prop
, value
, *ec
);
105 U_CAPI
void U_EXPORT2
106 uset_applyPropertyAlias(USet
* set
,
107 const UChar
*prop
, int32_t propLength
,
108 const UChar
*value
, int32_t valueLength
,
111 UnicodeString
p(prop
, propLength
);
112 UnicodeString
v(value
, valueLength
);
114 ((UnicodeSet
*) set
)->applyPropertyAlias(p
, v
, *ec
);
117 U_CAPI UBool U_EXPORT2
118 uset_resemblesPattern(const UChar
*pattern
, int32_t patternLength
,
121 UnicodeString
pat(pattern
, patternLength
);
123 return ((pos
+1) < pat
.length() &&
124 pat
.charAt(pos
) == (UChar
)91/*[*/) ||
125 UnicodeSet::resemblesPattern(pat
, pos
);
128 U_CAPI
int32_t U_EXPORT2
129 uset_toPattern(const USet
* set
,
130 UChar
* result
, int32_t resultCapacity
,
131 UBool escapeUnprintable
,
134 ((const UnicodeSet
*) set
)->toPattern(pat
, escapeUnprintable
);
135 return pat
.extract(result
, resultCapacity
, *ec
);