2 * Copyright (C) 2008-2009, 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
));
37 CollData
*data
= STATIC_CAST(CollData
*, ucd
);
39 CollData::close(data
);
42 U_CAPI UCollator
* U_EXPORT2
43 ucd_getCollator(UCD
*ucd
)
45 CollData
*data
= STATIC_CAST(CollData
*, ucd
);
47 return data
->getCollator();
53 CollData::freeCollDataCache();
59 CollData::flushCollDataCache();
64 BoyerMooreSearch
*bms
;
65 const UnicodeString
*targetString
;
68 U_CAPI BMS
* U_EXPORT2
70 const UChar
*pattern
, int32_t patternLength
,
71 const UChar
*target
, int32_t targetLength
,
74 BMS
*bms
= STATIC_CAST(BMS
*, uprv_malloc(sizeof(BMS
)));
77 *status
= U_MEMORY_ALLOCATION_ERROR
;
81 CollData
*data
= (CollData
*) ucd
;
82 UnicodeString
patternString(pattern
, patternLength
);
85 bms
->targetString
= new UnicodeString(target
, targetLength
);
87 if (bms
->targetString
== NULL
) {
89 *status
= U_MEMORY_ALLOCATION_ERROR
;
93 bms
->targetString
= NULL
;
96 bms
->bms
= new BoyerMooreSearch(data
, patternString
, bms
->targetString
, *status
);
98 if (bms
->bms
== NULL
) {
99 *status
= U_MEMORY_ALLOCATION_ERROR
;
105 U_CAPI
void U_EXPORT2
110 delete bms
->targetString
;
115 U_CAPI UBool U_EXPORT2
118 return bms
->bms
->empty();
121 U_CAPI UCD
* U_EXPORT2
122 bms_getData(BMS
*bms
)
124 return STATIC_CAST(UCD
*, bms
->bms
->getData());
127 U_CAPI UBool U_EXPORT2
128 bms_search(BMS
*bms
, int32_t offset
, int32_t *start
, int32_t *end
)
130 return bms
->bms
->search(offset
, *start
, *end
);
133 U_CAPI
void U_EXPORT2
134 bms_setTargetString(BMS
*bms
, const UChar
*target
, int32_t targetLength
, UErrorCode
*status
)
136 if (U_FAILURE(*status
)) {
140 if (bms
->targetString
!= NULL
) {
141 delete bms
->targetString
;
144 if (target
!= NULL
) {
145 bms
->targetString
= new UnicodeString(target
, targetLength
);
147 bms
->targetString
= NULL
;
150 bms
->bms
->setTargetString(bms
->targetString
, *status
);