2 **********************************************************************
3 * Copyright (c) 2002-2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 **********************************************************************
12 #include "unicode/unorm.h"
13 #include "unicode/ustring.h"
15 // Stubs for Windows API functions when building on UNIXes.
17 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
22 inline int FoldStringW(DWORD dwMapFlags
, const UChar
* lpSrcStr
,int cchSrc
, UChar
* lpDestStr
,int cchDest
);
25 #define DEST_BUFFER_CAPACITY 6000
26 typedef int32_t (*NormFn
)(const UChar
* src
,int32_t srcLen
, UChar
* dest
,int32_t dstLen
, int32_t options
, UErrorCode
* status
);
27 typedef int32_t (*QuickCheckFn
)(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
);
29 class QuickCheckPerfFunction
: public UPerfFunction
{
34 UNormalizationMode mode
;
43 virtual void call(UErrorCode
* status
){
46 for(int32_t i
= 0; i
< numLines
; i
++){
47 retVal
= (*fn
)(lines
[i
].name
,lines
[i
].len
,mode
, options
, status
);
50 for(int32_t i
= 0; i
< numLines
; i
++){
51 retVal
= (*fn
)(lines
[i
].name
,-1,mode
, options
, status
);
57 retVal
= (*fn
)(src
,srcLen
,mode
, options
, status
);
59 retVal
= (*fn
)(src
,-1,mode
, options
, status
);
64 virtual long getOperationsPerIteration(){
67 for(int32_t i
=0; i
< numLines
; i
++){
68 totalChars
+= lines
[i
].len
;
75 QuickCheckPerfFunction(QuickCheckFn func
, ULine
* srcLines
,int32_t srcNumLines
, UNormalizationMode _mode
, int32_t opts
, UBool _uselen
) : options(opts
) {
78 numLines
= srcNumLines
;
85 QuickCheckPerfFunction(QuickCheckFn func
, const UChar
* source
,int32_t sourceLen
, UNormalizationMode _mode
, int32_t opts
, UBool _uselen
) : options(opts
) {
98 class NormPerfFunction
: public UPerfFunction
{
102 UChar dest
[DEST_BUFFER_CAPACITY
];
114 virtual void call(UErrorCode
* status
){
117 for(int32_t i
= 0; i
< numLines
; i
++){
118 retVal
= (*fn
)(lines
[i
].name
,lines
[i
].len
,pDest
,destLen
, options
, status
);
121 for(int32_t i
= 0; i
< numLines
; i
++){
122 retVal
= (*fn
)(lines
[i
].name
,-1,pDest
,destLen
, options
, status
);
127 retVal
= (*fn
)(src
,srcLen
,pDest
,destLen
, options
, status
);
129 retVal
= (*fn
)(src
,-1,pDest
,destLen
, options
, status
);
133 virtual long getOperationsPerIteration(){
134 if(line_mode
==TRUE
){
135 int32_t totalChars
=0;
136 for(int32_t i
=0; i
< numLines
; i
++){
137 totalChars
+= lines
[i
].len
;
144 NormPerfFunction(NormFn func
, int32_t opts
, ULine
* srcLines
,int32_t srcNumLines
,UBool _uselen
) : options(opts
) {
147 numLines
= srcNumLines
;
149 destLen
= DEST_BUFFER_CAPACITY
;
155 NormPerfFunction(NormFn func
, int32_t opts
, const UChar
* source
,int32_t sourceLen
,UBool _uselen
) : options(opts
) {
160 destLen
= sourceLen
*3;
161 pDest
= (UChar
*) malloc(destLen
* U_SIZEOF_UCHAR
);
175 class NormalizerPerformanceTest
: public UPerfTest
{
182 int32_t origBufferLen
;
183 int32_t NFDBufferLen
;
184 int32_t NFCBufferLen
;
187 void normalizeInput(ULine
* dest
,const UChar
* src
,int32_t srcLen
,UNormalizationMode mode
, int32_t options
);
188 UChar
* normalizeInput(int32_t& len
, const UChar
* src
,int32_t srcLen
,UNormalizationMode mode
, int32_t options
);
192 NormalizerPerformanceTest(int32_t argc
, const char* argv
[], UErrorCode
& status
);
193 ~NormalizerPerformanceTest();
194 virtual UPerfFunction
* runIndexedTest(int32_t index
, UBool exec
,const char* &name
, char* par
= NULL
);
195 /* NFC performance */
196 UPerfFunction
* TestICU_NFC_NFD_Text();
197 UPerfFunction
* TestICU_NFC_NFC_Text();
198 UPerfFunction
* TestICU_NFC_Orig_Text();
200 /* NFD performance */
201 UPerfFunction
* TestICU_NFD_NFD_Text();
202 UPerfFunction
* TestICU_NFD_NFC_Text();
203 UPerfFunction
* TestICU_NFD_Orig_Text();
205 /* FCD performance */
206 UPerfFunction
* TestICU_FCD_NFD_Text();
207 UPerfFunction
* TestICU_FCD_NFC_Text();
208 UPerfFunction
* TestICU_FCD_Orig_Text();
210 /*Win NFC performance */
211 UPerfFunction
* TestWin_NFC_NFD_Text();
212 UPerfFunction
* TestWin_NFC_NFC_Text();
213 UPerfFunction
* TestWin_NFC_Orig_Text();
215 /* Win NFD performance */
216 UPerfFunction
* TestWin_NFD_NFD_Text();
217 UPerfFunction
* TestWin_NFD_NFC_Text();
218 UPerfFunction
* TestWin_NFD_Orig_Text();
220 /* Quick check performance */
221 UPerfFunction
* TestQC_NFC_NFD_Text();
222 UPerfFunction
* TestQC_NFC_NFC_Text();
223 UPerfFunction
* TestQC_NFC_Orig_Text();
225 UPerfFunction
* TestQC_NFD_NFD_Text();
226 UPerfFunction
* TestQC_NFD_NFC_Text();
227 UPerfFunction
* TestQC_NFD_Orig_Text();
229 UPerfFunction
* TestQC_FCD_NFD_Text();
230 UPerfFunction
* TestQC_FCD_NFC_Text();
231 UPerfFunction
* TestQC_FCD_Orig_Text();
233 /* IsNormalized performnace */
234 UPerfFunction
* TestIsNormalized_NFC_NFD_Text();
235 UPerfFunction
* TestIsNormalized_NFC_NFC_Text();
236 UPerfFunction
* TestIsNormalized_NFC_Orig_Text();
238 UPerfFunction
* TestIsNormalized_NFD_NFD_Text();
239 UPerfFunction
* TestIsNormalized_NFD_NFC_Text();
240 UPerfFunction
* TestIsNormalized_NFD_Orig_Text();
242 UPerfFunction
* TestIsNormalized_FCD_NFD_Text();
243 UPerfFunction
* TestIsNormalized_FCD_NFC_Text();
244 UPerfFunction
* TestIsNormalized_FCD_Orig_Text();
248 //---------------------------------------------------------------------------------------
249 // Platform / ICU version specific proto-types
250 //---------------------------------------------------------------------------------------
253 #if (U_ICU_VERSION_MAJOR_NUM > 1 ) || ((U_ICU_VERSION_MAJOR_NUM == 1 )&&(U_ICU_VERSION_MINOR_NUM > 8) && (U_ICU_VERSION_PATCHLEVEL_NUM >=1))
255 int32_t ICUNormNFD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
256 return unorm_normalize(src
,srcLen
,UNORM_NFD
, options
,dest
,dstLen
,status
);
259 int32_t ICUNormNFC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
260 return unorm_normalize(src
,srcLen
,UNORM_NFC
, options
,dest
,dstLen
,status
);
263 int32_t ICUNormNFKD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
264 return unorm_normalize(src
,srcLen
,UNORM_NFKD
, options
,dest
,dstLen
,status
);
266 int32_t ICUNormNFKC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
267 return unorm_normalize(src
,srcLen
,UNORM_NFKC
, options
,dest
,dstLen
,status
);
270 int32_t ICUNormFCD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
271 return unorm_normalize(src
,srcLen
,UNORM_FCD
, options
,dest
,dstLen
,status
);
274 int32_t ICUQuickCheck(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
275 #if (U_ICU_VERSION_MAJOR_NUM > 2 ) || ((U_ICU_VERSION_MAJOR_NUM == 2 )&&(U_ICU_VERSION_MINOR_NUM >= 6))
276 return unorm_quickCheckWithOptions(src
,srcLen
,mode
, options
, status
);
278 return unorm_quickCheck(src
,srcLen
,mode
,status
);
281 int32_t ICUIsNormalized(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
282 return unorm_isNormalized(src
,srcLen
,mode
,status
);
288 int32_t ICUNormNFD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
289 return unorm_normalize(src
,srcLen
,UCOL_DECOMP_CAN
, options
,dest
,dstLen
,status
);
292 int32_t ICUNormNFC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
293 return unorm_normalize(src
,srcLen
,UCOL_COMPOSE_CAN
, options
,dest
,dstLen
,status
);
296 int32_t ICUNormNFKD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
297 return unorm_normalize(src
,srcLen
,UCOL_DECOMP_COMPAT
, options
,dest
,dstLen
,status
);
299 int32_t ICUNormNFKC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
300 return unorm_normalize(src
,srcLen
,UCOL_COMPOSE_COMPAT
, options
,dest
,dstLen
,status
);
303 int32_t ICUNormFCD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
304 return unorm_normalize(src
,srcLen
,UNORM_FCD
, options
,dest
,dstLen
,status
);
307 int32_t ICUQuickCheck(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
308 return unorm_quickCheck(src
,srcLen
,mode
,status
);
311 int32_t ICUIsNormalized(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
316 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
318 int32_t WinNormNFD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
319 return FoldStringW(MAP_COMPOSITE
,src
,srcLen
,dest
,dstLen
);
322 int32_t WinNormNFC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
323 return FoldStringW(MAP_PRECOMPOSED
,src
,srcLen
,dest
,dstLen
);
326 int32_t WinNormNFKD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
327 return FoldStringW(MAP_COMPOSITE
+MAP_FOLDCZONE
,src
,srcLen
,dest
,dstLen
);
329 int32_t WinNormNFKC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
330 return FoldStringW(MAP_FOLDCZONE
,src
,srcLen
,dest
,dstLen
);
333 int32_t WinNormNFD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
337 int32_t WinNormNFC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
341 int32_t WinNormNFKD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
344 int32_t WinNormNFKC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {