2 * Copyright (C) 2008-2011, International Business Machines Corporation and Others.
6 #include "unicode/utypes.h"
8 #include "unicode/bms.h"
9 #include "unicode/unistr.h"
10 #include "unicode/colldata.h"
11 #include "unicode/bmsearch.h"
14 #if !UCONFIG_NO_COLLATION && !UCONFIG_NO_BREAK_ITERATION
17 //#define USE_SAFE_CASTS
19 #define STATIC_CAST(type,value) static_cast<type>(value)
20 #define CONST_CAST(type,value) const_cast<type>(value)
22 #define STATIC_CAST(type,value) (type) (value)
23 #define CONST_CAST(type,value) (type) (value)
28 U_CAPI UCD
* U_EXPORT2
29 ucd_open(UCollator
*coll
, UErrorCode
*status
)
31 return STATIC_CAST(UCD
*, CollData::open(coll
, *status
));
38 CollData
*data
= STATIC_CAST(CollData
*, ucd
);
40 CollData::close(data
);
44 U_CAPI UCollator
* U_EXPORT2
45 ucd_getCollator(UCD
*ucd
)
47 CollData
*data
= STATIC_CAST(CollData
*, ucd
);
49 return data
->getCollator();
55 CollData::freeCollDataCache();
61 CollData::flushCollDataCache();
66 BoyerMooreSearch
*bms
;
67 const UnicodeString
*targetString
;
70 U_CAPI BMS
* U_EXPORT2
72 const UChar
*pattern
, int32_t patternLength
,
73 const UChar
*target
, int32_t targetLength
,
76 BMS
*bms
= STATIC_CAST(BMS
*, uprv_malloc(sizeof(BMS
)));
79 *status
= U_MEMORY_ALLOCATION_ERROR
;
83 CollData
*data
= (CollData
*) ucd
;
84 UnicodeString
patternString(pattern
, patternLength
);
87 bms
->targetString
= new UnicodeString(target
, targetLength
);
89 if (bms
->targetString
== NULL
) {
91 *status
= U_MEMORY_ALLOCATION_ERROR
;
95 bms
->targetString
= NULL
;
98 bms
->bms
= new BoyerMooreSearch(data
, patternString
, bms
->targetString
, *status
);
100 if (bms
->bms
== NULL
) {
101 *status
= U_MEMORY_ALLOCATION_ERROR
;
107 U_CAPI
void U_EXPORT2
112 delete bms
->targetString
;
117 U_CAPI UBool U_EXPORT2
120 return bms
->bms
->empty();
123 U_CAPI UCD
* U_EXPORT2
124 bms_getData(BMS
*bms
)
126 return STATIC_CAST(UCD
*, bms
->bms
->getData());
129 U_CAPI UBool U_EXPORT2
130 bms_search(BMS
*bms
, int32_t offset
, int32_t *start
, int32_t *end
)
132 return bms
->bms
->search(offset
, *start
, *end
);
135 U_CAPI
void U_EXPORT2
136 bms_setTargetString(BMS
*bms
, const UChar
*target
, int32_t targetLength
, UErrorCode
*status
)
138 if (U_FAILURE(*status
)) {
142 if (bms
->targetString
!= NULL
) {
143 delete bms
->targetString
;
146 if (target
!= NULL
) {
147 bms
->targetString
= new UnicodeString(target
, targetLength
);
149 bms
->targetString
= NULL
;
152 bms
->bms
->setTargetString(bms
->targetString
, *status
);