2 **********************************************************************
3 * Copyright (c) 2002-2011, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
6 **********************************************************************
11 #include "unicode/unorm.h"
12 #include "unicode/ustring.h"
14 #include "unicode/uperf.h"
17 // Stubs for Windows API functions when building on UNIXes.
19 #if U_PLATFORM_USES_ONLY_WIN32_API
24 inline int FoldStringW(DWORD dwMapFlags
, const UChar
* lpSrcStr
,int cchSrc
, UChar
* lpDestStr
,int cchDest
);
27 #define DEST_BUFFER_CAPACITY 6000
28 typedef int32_t (*NormFn
)(const UChar
* src
,int32_t srcLen
, UChar
* dest
,int32_t dstLen
, int32_t options
, UErrorCode
* status
);
29 typedef int32_t (*QuickCheckFn
)(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
);
31 class QuickCheckPerfFunction
: public UPerfFunction
{
36 UNormalizationMode mode
;
45 virtual void call(UErrorCode
* status
){
48 for(int32_t i
= 0; i
< numLines
; i
++){
49 retVal
= (*fn
)(lines
[i
].name
,lines
[i
].len
,mode
, options
, status
);
52 for(int32_t i
= 0; i
< numLines
; i
++){
53 retVal
= (*fn
)(lines
[i
].name
,-1,mode
, options
, status
);
59 retVal
= (*fn
)(src
,srcLen
,mode
, options
, status
);
61 retVal
= (*fn
)(src
,-1,mode
, options
, status
);
66 virtual long getOperationsPerIteration(){
69 for(int32_t i
=0; i
< numLines
; i
++){
70 totalChars
+= lines
[i
].len
;
77 QuickCheckPerfFunction(QuickCheckFn func
, ULine
* srcLines
,int32_t srcNumLines
, UNormalizationMode _mode
, int32_t opts
, UBool _uselen
) : options(opts
) {
80 numLines
= srcNumLines
;
87 QuickCheckPerfFunction(QuickCheckFn func
, const UChar
* source
,int32_t sourceLen
, UNormalizationMode _mode
, int32_t opts
, UBool _uselen
) : options(opts
) {
100 class NormPerfFunction
: public UPerfFunction
{
104 UChar dest
[DEST_BUFFER_CAPACITY
];
116 virtual void call(UErrorCode
* status
){
119 for(int32_t i
= 0; i
< numLines
; i
++){
120 retVal
= (*fn
)(lines
[i
].name
,lines
[i
].len
,pDest
,destLen
, options
, status
);
123 for(int32_t i
= 0; i
< numLines
; i
++){
124 retVal
= (*fn
)(lines
[i
].name
,-1,pDest
,destLen
, options
, status
);
129 retVal
= (*fn
)(src
,srcLen
,pDest
,destLen
, options
, status
);
131 retVal
= (*fn
)(src
,-1,pDest
,destLen
, options
, status
);
135 virtual long getOperationsPerIteration(){
136 if(line_mode
==TRUE
){
137 int32_t totalChars
=0;
138 for(int32_t i
=0; i
< numLines
; i
++){
139 totalChars
+= lines
[i
].len
;
146 NormPerfFunction(NormFn func
, int32_t opts
, ULine
* srcLines
,int32_t srcNumLines
,UBool _uselen
) : options(opts
) {
149 numLines
= srcNumLines
;
151 destLen
= DEST_BUFFER_CAPACITY
;
157 NormPerfFunction(NormFn func
, int32_t opts
, const UChar
* source
,int32_t sourceLen
,UBool _uselen
) : options(opts
) {
162 destLen
= sourceLen
*3;
163 pDest
= (UChar
*) malloc(destLen
* U_SIZEOF_UCHAR
);
177 class NormalizerPerformanceTest
: public UPerfTest
{
184 int32_t origBufferLen
;
185 int32_t NFDBufferLen
;
186 int32_t NFCBufferLen
;
189 void normalizeInput(ULine
* dest
,const UChar
* src
,int32_t srcLen
,UNormalizationMode mode
, int32_t options
);
190 UChar
* normalizeInput(int32_t& len
, const UChar
* src
,int32_t srcLen
,UNormalizationMode mode
, int32_t options
);
194 NormalizerPerformanceTest(int32_t argc
, const char* argv
[], UErrorCode
& status
);
195 ~NormalizerPerformanceTest();
196 virtual UPerfFunction
* runIndexedTest(int32_t index
, UBool exec
,const char* &name
, char* par
= NULL
);
197 /* NFC performance */
198 UPerfFunction
* TestICU_NFC_NFD_Text();
199 UPerfFunction
* TestICU_NFC_NFC_Text();
200 UPerfFunction
* TestICU_NFC_Orig_Text();
202 /* NFD performance */
203 UPerfFunction
* TestICU_NFD_NFD_Text();
204 UPerfFunction
* TestICU_NFD_NFC_Text();
205 UPerfFunction
* TestICU_NFD_Orig_Text();
207 /* FCD performance */
208 UPerfFunction
* TestICU_FCD_NFD_Text();
209 UPerfFunction
* TestICU_FCD_NFC_Text();
210 UPerfFunction
* TestICU_FCD_Orig_Text();
212 /*Win NFC performance */
213 UPerfFunction
* TestWin_NFC_NFD_Text();
214 UPerfFunction
* TestWin_NFC_NFC_Text();
215 UPerfFunction
* TestWin_NFC_Orig_Text();
217 /* Win NFD performance */
218 UPerfFunction
* TestWin_NFD_NFD_Text();
219 UPerfFunction
* TestWin_NFD_NFC_Text();
220 UPerfFunction
* TestWin_NFD_Orig_Text();
222 /* Quick check performance */
223 UPerfFunction
* TestQC_NFC_NFD_Text();
224 UPerfFunction
* TestQC_NFC_NFC_Text();
225 UPerfFunction
* TestQC_NFC_Orig_Text();
227 UPerfFunction
* TestQC_NFD_NFD_Text();
228 UPerfFunction
* TestQC_NFD_NFC_Text();
229 UPerfFunction
* TestQC_NFD_Orig_Text();
231 UPerfFunction
* TestQC_FCD_NFD_Text();
232 UPerfFunction
* TestQC_FCD_NFC_Text();
233 UPerfFunction
* TestQC_FCD_Orig_Text();
235 /* IsNormalized performnace */
236 UPerfFunction
* TestIsNormalized_NFC_NFD_Text();
237 UPerfFunction
* TestIsNormalized_NFC_NFC_Text();
238 UPerfFunction
* TestIsNormalized_NFC_Orig_Text();
240 UPerfFunction
* TestIsNormalized_NFD_NFD_Text();
241 UPerfFunction
* TestIsNormalized_NFD_NFC_Text();
242 UPerfFunction
* TestIsNormalized_NFD_Orig_Text();
244 UPerfFunction
* TestIsNormalized_FCD_NFD_Text();
245 UPerfFunction
* TestIsNormalized_FCD_NFC_Text();
246 UPerfFunction
* TestIsNormalized_FCD_Orig_Text();
250 //---------------------------------------------------------------------------------------
251 // Platform / ICU version specific proto-types
252 //---------------------------------------------------------------------------------------
255 #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))
257 int32_t ICUNormNFD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
258 return unorm_normalize(src
,srcLen
,UNORM_NFD
, options
,dest
,dstLen
,status
);
261 int32_t ICUNormNFC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
262 return unorm_normalize(src
,srcLen
,UNORM_NFC
, options
,dest
,dstLen
,status
);
265 int32_t ICUNormNFKD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
266 return unorm_normalize(src
,srcLen
,UNORM_NFKD
, options
,dest
,dstLen
,status
);
268 int32_t ICUNormNFKC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
269 return unorm_normalize(src
,srcLen
,UNORM_NFKC
, options
,dest
,dstLen
,status
);
272 int32_t ICUNormFCD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
273 return unorm_normalize(src
,srcLen
,UNORM_FCD
, options
,dest
,dstLen
,status
);
276 int32_t ICUQuickCheck(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
277 #if (U_ICU_VERSION_MAJOR_NUM > 2 ) || ((U_ICU_VERSION_MAJOR_NUM == 2 )&&(U_ICU_VERSION_MINOR_NUM >= 6))
278 return unorm_quickCheckWithOptions(src
,srcLen
,mode
, options
, status
);
280 return unorm_quickCheck(src
,srcLen
,mode
,status
);
283 int32_t ICUIsNormalized(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
284 return unorm_isNormalized(src
,srcLen
,mode
,status
);
290 int32_t ICUNormNFD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
291 return unorm_normalize(src
,srcLen
,UCOL_DECOMP_CAN
, options
,dest
,dstLen
,status
);
294 int32_t ICUNormNFC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
295 return unorm_normalize(src
,srcLen
,UCOL_COMPOSE_CAN
, options
,dest
,dstLen
,status
);
298 int32_t ICUNormNFKD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
299 return unorm_normalize(src
,srcLen
,UCOL_DECOMP_COMPAT
, options
,dest
,dstLen
,status
);
301 int32_t ICUNormNFKC(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
302 return unorm_normalize(src
,srcLen
,UCOL_COMPOSE_COMPAT
, options
,dest
,dstLen
,status
);
305 int32_t ICUNormFCD(const UChar
* src
, int32_t srcLen
,UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
306 return unorm_normalize(src
,srcLen
,UNORM_FCD
, options
,dest
,dstLen
,status
);
309 int32_t ICUQuickCheck(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
310 return unorm_quickCheck(src
,srcLen
,mode
,status
);
313 int32_t ICUIsNormalized(const UChar
* src
,int32_t srcLen
, UNormalizationMode mode
, int32_t options
, UErrorCode
* status
){
318 #if U_PLATFORM_HAS_WIN32_API
320 int32_t WinNormNFD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
321 return FoldStringW(MAP_COMPOSITE
,src
,srcLen
,dest
,dstLen
);
324 int32_t WinNormNFC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
325 return FoldStringW(MAP_PRECOMPOSED
,src
,srcLen
,dest
,dstLen
);
328 int32_t WinNormNFKD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
329 return FoldStringW(MAP_COMPOSITE
+MAP_FOLDCZONE
,src
,srcLen
,dest
,dstLen
);
331 int32_t WinNormNFKC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
332 return FoldStringW(MAP_FOLDCZONE
,src
,srcLen
,dest
,dstLen
);
335 int32_t WinNormNFD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
339 int32_t WinNormNFC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
343 int32_t WinNormNFKD(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {
346 int32_t WinNormNFKC(const UChar
* src
, int32_t srcLen
, UChar
* dest
, int32_t dstLen
, int32_t options
, UErrorCode
* status
) {