]>
Commit | Line | Data |
---|---|---|
374ca955 A |
1 | /* |
2 | ******************************************************************************* | |
3 | * | |
73c04bcf | 4 | * Copyright (C) 2002-2005, International Business Machines |
374ca955 A |
5 | * Corporation and others. All Rights Reserved. |
6 | * | |
7 | ******************************************************************************* | |
8 | * file name: uset_props.cpp | |
9 | * encoding: US-ASCII | |
10 | * tab size: 8 (not used) | |
11 | * indentation:4 | |
12 | * | |
13 | * created on: 2004aug30 | |
14 | * created by: Markus W. Scherer | |
15 | * | |
16 | * C wrappers around UnicodeSet functions that are implemented in | |
17 | * uniset_props.cpp, split off for modularization. | |
18 | */ | |
19 | ||
20 | #include "unicode/utypes.h" | |
21 | #include "unicode/uobject.h" | |
22 | #include "unicode/uset.h" | |
23 | #include "unicode/uniset.h" | |
24 | #include "cmemory.h" | |
25 | #include "unicode/ustring.h" | |
26 | #include "unicode/parsepos.h" | |
27 | ||
28 | U_CAPI USet* U_EXPORT2 | |
29 | uset_openPattern(const UChar* pattern, int32_t patternLength, | |
30 | UErrorCode* ec) | |
31 | { | |
32 | UnicodeString pat(patternLength==-1, pattern, patternLength); | |
33 | UnicodeSet* set = new UnicodeSet(pat, *ec); | |
34 | /* test for NULL */ | |
35 | if(set == 0) { | |
36 | *ec = U_MEMORY_ALLOCATION_ERROR; | |
37 | return 0; | |
38 | } | |
39 | ||
40 | if (U_FAILURE(*ec)) { | |
41 | delete set; | |
42 | set = NULL; | |
43 | } | |
44 | return (USet*) set; | |
45 | } | |
46 | ||
47 | U_CAPI USet* U_EXPORT2 | |
48 | uset_openPatternOptions(const UChar* pattern, int32_t patternLength, | |
49 | uint32_t options, | |
50 | UErrorCode* ec) | |
51 | { | |
52 | UnicodeString pat(patternLength==-1, pattern, patternLength); | |
53 | UnicodeSet* set = new UnicodeSet(pat, options, NULL, *ec); | |
54 | /* test for NULL */ | |
55 | if(set == 0) { | |
56 | *ec = U_MEMORY_ALLOCATION_ERROR; | |
57 | return 0; | |
58 | } | |
59 | ||
60 | if (U_FAILURE(*ec)) { | |
61 | delete set; | |
62 | set = NULL; | |
63 | } | |
64 | return (USet*) set; | |
65 | } | |
66 | ||
67 | ||
68 | U_CAPI int32_t U_EXPORT2 | |
69 | uset_applyPattern(USet *set, | |
70 | const UChar *pattern, int32_t patternLength, | |
71 | uint32_t options, | |
72 | UErrorCode *status){ | |
73 | ||
74 | // status code needs to be checked since we | |
75 | // dereference it | |
76 | if(status == NULL || U_FAILURE(*status)){ | |
77 | return 0; | |
78 | } | |
79 | ||
80 | // check only the set paramenter | |
81 | // if pattern is NULL or null terminate | |
82 | // UnicodeString constructor takes care of it | |
83 | if(set == NULL){ | |
84 | *status = U_ILLEGAL_ARGUMENT_ERROR; | |
85 | return 0; | |
86 | } | |
87 | ||
88 | UnicodeString pat(pattern, patternLength); | |
89 | ||
90 | ParsePosition pos; | |
91 | ||
92 | ((UnicodeSet*) set)->applyPattern(pat, pos, options, NULL, *status); | |
93 | ||
94 | return pos.getIndex(); | |
95 | } | |
96 | ||
97 | U_CAPI void U_EXPORT2 | |
98 | uset_applyIntPropertyValue(USet* set, | |
99 | UProperty prop, int32_t value, UErrorCode* ec) { | |
100 | ((UnicodeSet*) set)->applyIntPropertyValue(prop, value, *ec); | |
101 | } | |
102 | ||
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, | |
107 | UErrorCode* ec) { | |
108 | ||
109 | UnicodeString p(prop, propLength); | |
110 | UnicodeString v(value, valueLength); | |
111 | ||
112 | ((UnicodeSet*) set)->applyPropertyAlias(p, v, *ec); | |
113 | } | |
114 | ||
115 | U_CAPI UBool U_EXPORT2 | |
116 | uset_resemblesPattern(const UChar *pattern, int32_t patternLength, | |
117 | int32_t pos) { | |
118 | ||
119 | UnicodeString pat(pattern, patternLength); | |
120 | ||
121 | return ((pos+1) < pat.length() && | |
122 | pat.charAt(pos) == (UChar)91/*[*/) || | |
123 | UnicodeSet::resemblesPattern(pat, pos); | |
124 | } | |
125 | ||
126 | U_CAPI int32_t U_EXPORT2 | |
127 | uset_toPattern(const USet* set, | |
128 | UChar* result, int32_t resultCapacity, | |
129 | UBool escapeUnprintable, | |
130 | UErrorCode* ec) { | |
131 | UnicodeString pat; | |
132 | ((const UnicodeSet*) set)->toPattern(pat, escapeUnprintable); | |
133 | return pat.extract(result, resultCapacity, *ec); | |
134 | } |