Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/sqlite/src/ext/icu/icu.c

Issue 1880263002: [sqlite] Backport icuCaseFunc16 patch from SQLite. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 ** 2007 May 6 2 ** 2007 May 6
3 ** 3 **
4 ** The author disclaims copyright to this source code. In place of 4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing: 5 ** a legal notice, here is a blessing:
6 ** 6 **
7 ** May you do good and not evil. 7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others. 8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give. 9 ** May you share freely, never taking more than you give.
10 ** 10 **
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 ** as the second argument is the same as invoking the 1 argument version 318 ** as the second argument is the same as invoking the 1 argument version
319 ** of upper() or lower(). 319 ** of upper() or lower().
320 ** 320 **
321 ** lower('I', 'en_us') -> 'i' 321 ** lower('I', 'en_us') -> 'i'
322 ** lower('I', 'tr_tr') -> 'ı' (small dotless i) 322 ** lower('I', 'tr_tr') -> 'ı' (small dotless i)
323 ** 323 **
324 ** http://www.icu-project.org/userguide/posix.html#case_mappings 324 ** http://www.icu-project.org/userguide/posix.html#case_mappings
325 */ 325 */
326 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ 326 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
327 const UChar *zInput; 327 const UChar *zInput;
328 UChar *zOutput; 328 UChar *zOutput = 0;
329 int nInput; 329 int nInput;
330 int nOutput; 330 int nOut;
331 331 int cnt;
332 UErrorCode status = U_ZERO_ERROR; 332 UErrorCode status;
333 const char *zLocale = 0; 333 const char *zLocale = 0;
334 334
335 assert(nArg==1 || nArg==2); 335 assert(nArg==1 || nArg==2);
336 if( nArg==2 ){ 336 if( nArg==2 ){
337 zLocale = (const char *)sqlite3_value_text(apArg[1]); 337 zLocale = (const char *)sqlite3_value_text(apArg[1]);
338 } 338 }
339 339
340 zInput = sqlite3_value_text16(apArg[0]); 340 zInput = sqlite3_value_text16(apArg[0]);
341 if( !zInput ){ 341 if( !zInput ){
342 return; 342 return;
343 } 343 }
344 nOutput = nInput = sqlite3_value_bytes16(apArg[0]); 344 nOut = nInput = sqlite3_value_bytes16(apArg[0]);
345 345 if( nOut==0 ){
346 zOutput = sqlite3_malloc(nOutput); 346 sqlite3_result_text16(p, "", 0, SQLITE_STATIC);
347 if( !zOutput ){
348 return; 347 return;
349 } 348 }
350 349
351 if( sqlite3_user_data(p) ){ 350 for(cnt=0; cnt<2; cnt++){
352 nOutput = u_strToUpper( 351 UChar *zNew = sqlite3_realloc(zOutput, nOut);
353 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2; 352 if( zNew==0 ){
354 }else{
355 nOutput = u_strToLower(
356 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2;
357 }
358
359 if ( status == U_BUFFER_OVERFLOW_ERROR ) {
360 UChar* newOutput = sqlite3_realloc(zOutput, nOutput);
361 if( !newOutput ){
362 sqlite3_free(zOutput); 353 sqlite3_free(zOutput);
354 sqlite3_result_error_nomem(p);
363 return; 355 return;
364 } 356 }
365 zOutput = newOutput; 357 zOutput = zNew;
366 status = U_ZERO_ERROR; 358 status = U_ZERO_ERROR;
367 if( sqlite3_user_data(p) ){ 359 if( sqlite3_user_data(p) ){
368 nOutput = u_strToUpper( 360 nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
369 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2;
370 }else{ 361 }else{
371 nOutput = u_strToLower( 362 nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
372 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2; 363 }
364 if( !U_SUCCESS(status) ){
365 if( status==U_BUFFER_OVERFLOW_ERROR ) continue;
366 icuFunctionError(p,
367 sqlite3_user_data(p) ? "u_strToUpper()" : "u_strToLower", status);
368 return;
373 } 369 }
374 } 370 }
375 371 sqlite3_result_text16(p, zOutput, nOut, xFree);
376 if( U_FAILURE(status) ){
377 icuFunctionError(p, "u_strToLower()/u_strToUpper", status);
378 sqlite3_free(zOutput);
379 return;
380 }
381
382 sqlite3_result_text16(p, zOutput, nOutput, xFree);
383 } 372 }
384 373
385 /* 374 /*
386 ** Collation sequence destructor function. The pCtx argument points to 375 ** Collation sequence destructor function. The pCtx argument points to
387 ** a UCollator structure previously allocated using ucol_open(). 376 ** a UCollator structure previously allocated using ucol_open().
388 */ 377 */
389 static void icuCollationDel(void *pCtx){ 378 static void icuCollationDel(void *pCtx){
390 UCollator *p = (UCollator *)pCtx; 379 UCollator *p = (UCollator *)pCtx;
391 ucol_close(p); 380 ucol_close(p);
392 } 381 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 sqlite3 *db, 503 sqlite3 *db,
515 char **pzErrMsg, 504 char **pzErrMsg,
516 const sqlite3_api_routines *pApi 505 const sqlite3_api_routines *pApi
517 ){ 506 ){
518 SQLITE_EXTENSION_INIT2(pApi) 507 SQLITE_EXTENSION_INIT2(pApi)
519 return sqlite3IcuInit(db); 508 return sqlite3IcuInit(db);
520 } 509 }
521 #endif 510 #endif
522 511
523 #endif 512 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698