| OLD | NEW |
| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 ** as the second argument is the same as invoking the 1 argument version | 348 ** as the second argument is the same as invoking the 1 argument version |
| 349 ** of upper() or lower(). | 349 ** of upper() or lower(). |
| 350 ** | 350 ** |
| 351 ** lower('I', 'en_us') -> 'i' | 351 ** lower('I', 'en_us') -> 'i' |
| 352 ** lower('I', 'tr_tr') -> 'ı' (small dotless i) | 352 ** lower('I', 'tr_tr') -> 'ı' (small dotless i) |
| 353 ** | 353 ** |
| 354 ** http://www.icu-project.org/userguide/posix.html#case_mappings | 354 ** http://www.icu-project.org/userguide/posix.html#case_mappings |
| 355 */ | 355 */ |
| 356 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ | 356 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 357 const UChar *zInput; | 357 const UChar *zInput; |
| 358 UChar *zOutput; | 358 UChar *zOutput = 0; |
| 359 int nInput; | 359 int nInput; |
| 360 int nOutput; | 360 int nOut; |
| 361 | 361 int cnt; |
| 362 UErrorCode status = U_ZERO_ERROR; | 362 UErrorCode status; |
| 363 const char *zLocale = 0; | 363 const char *zLocale = 0; |
| 364 | 364 |
| 365 assert(nArg==1 || nArg==2); | 365 assert(nArg==1 || nArg==2); |
| 366 if( nArg==2 ){ | 366 if( nArg==2 ){ |
| 367 zLocale = (const char *)sqlite3_value_text(apArg[1]); | 367 zLocale = (const char *)sqlite3_value_text(apArg[1]); |
| 368 } | 368 } |
| 369 | 369 |
| 370 zInput = sqlite3_value_text16(apArg[0]); | 370 zInput = sqlite3_value_text16(apArg[0]); |
| 371 if( !zInput ){ | 371 if( !zInput ){ |
| 372 return; | 372 return; |
| 373 } | 373 } |
| 374 nOutput = nInput = sqlite3_value_bytes16(apArg[0]); | 374 nOut = nInput = sqlite3_value_bytes16(apArg[0]); |
| 375 | 375 if( nOut==0 ){ |
| 376 zOutput = sqlite3_malloc(nOutput); | 376 sqlite3_result_text16(p, "", 0, SQLITE_STATIC); |
| 377 if( !zOutput ){ | |
| 378 return; | 377 return; |
| 379 } | 378 } |
| 380 | 379 |
| 381 if( sqlite3_user_data(p) ){ | 380 for(cnt=0; cnt<2; cnt++){ |
| 382 nOutput = u_strToUpper( | 381 UChar *zNew = sqlite3_realloc(zOutput, nOut); |
| 383 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2; | 382 if( zNew==0 ){ |
| 384 }else{ | |
| 385 nOutput = u_strToLower( | |
| 386 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2; | |
| 387 } | |
| 388 | |
| 389 if ( status == U_BUFFER_OVERFLOW_ERROR ) { | |
| 390 UChar* newOutput = sqlite3_realloc(zOutput, nOutput); | |
| 391 if( !newOutput ){ | |
| 392 sqlite3_free(zOutput); | 383 sqlite3_free(zOutput); |
| 384 sqlite3_result_error_nomem(p); |
| 393 return; | 385 return; |
| 394 } | 386 } |
| 395 zOutput = newOutput; | 387 zOutput = zNew; |
| 396 status = U_ZERO_ERROR; | 388 status = U_ZERO_ERROR; |
| 397 if( sqlite3_user_data(p) ){ | 389 if( sqlite3_user_data(p) ){ |
| 398 nOutput = u_strToUpper( | 390 nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 399 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2; | |
| 400 }else{ | 391 }else{ |
| 401 nOutput = u_strToLower( | 392 nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 402 zOutput, nOutput/2, zInput, nInput/2, zLocale, &status) * 2; | 393 } |
| 394 if( !U_SUCCESS(status) ){ |
| 395 if( status==U_BUFFER_OVERFLOW_ERROR ) continue; |
| 396 icuFunctionError(p, |
| 397 sqlite3_user_data(p) ? "u_strToUpper()" : "u_strToLower", status); |
| 398 return; |
| 403 } | 399 } |
| 404 } | 400 } |
| 405 | 401 sqlite3_result_text16(p, zOutput, nOut, xFree); |
| 406 if( U_FAILURE(status) ){ | |
| 407 icuFunctionError(p, "u_strToLower()/u_strToUpper", status); | |
| 408 sqlite3_free(zOutput); | |
| 409 return; | |
| 410 } | |
| 411 | |
| 412 sqlite3_result_text16(p, zOutput, nOutput, xFree); | |
| 413 } | 402 } |
| 414 | 403 |
| 415 /* | 404 /* |
| 416 ** Collation sequence destructor function. The pCtx argument points to | 405 ** Collation sequence destructor function. The pCtx argument points to |
| 417 ** a UCollator structure previously allocated using ucol_open(). | 406 ** a UCollator structure previously allocated using ucol_open(). |
| 418 */ | 407 */ |
| 419 static void icuCollationDel(void *pCtx){ | 408 static void icuCollationDel(void *pCtx){ |
| 420 UCollator *p = (UCollator *)pCtx; | 409 UCollator *p = (UCollator *)pCtx; |
| 421 ucol_close(p); | 410 ucol_close(p); |
| 422 } | 411 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 sqlite3 *db, | 533 sqlite3 *db, |
| 545 char **pzErrMsg, | 534 char **pzErrMsg, |
| 546 const sqlite3_api_routines *pApi | 535 const sqlite3_api_routines *pApi |
| 547 ){ | 536 ){ |
| 548 SQLITE_EXTENSION_INIT2(pApi) | 537 SQLITE_EXTENSION_INIT2(pApi) |
| 549 return sqlite3IcuInit(db); | 538 return sqlite3IcuInit(db); |
| 550 } | 539 } |
| 551 #endif | 540 #endif |
| 552 | 541 |
| 553 #endif | 542 #endif |
| OLD | NEW |