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

Side by Side Diff: third_party/sqlite/src/src/utf.c

Issue 2751253002: [sql] Import SQLite 3.17.0. (Closed)
Patch Set: also clang on Linux i386 Created 3 years, 9 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
« no previous file with comments | « third_party/sqlite/src/src/update.c ('k') | third_party/sqlite/src/src/util.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 ** 2004 April 13 2 ** 2004 April 13
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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 /* If the translation is between UTF-16 little and big endian, then 224 /* If the translation is between UTF-16 little and big endian, then
225 ** all that is required is to swap the byte order. This case is handled 225 ** all that is required is to swap the byte order. This case is handled
226 ** differently from the others. 226 ** differently from the others.
227 */ 227 */
228 if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){ 228 if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){
229 u8 temp; 229 u8 temp;
230 int rc; 230 int rc;
231 rc = sqlite3VdbeMemMakeWriteable(pMem); 231 rc = sqlite3VdbeMemMakeWriteable(pMem);
232 if( rc!=SQLITE_OK ){ 232 if( rc!=SQLITE_OK ){
233 assert( rc==SQLITE_NOMEM ); 233 assert( rc==SQLITE_NOMEM );
234 return SQLITE_NOMEM; 234 return SQLITE_NOMEM_BKPT;
235 } 235 }
236 zIn = (u8*)pMem->z; 236 zIn = (u8*)pMem->z;
237 zTerm = &zIn[pMem->n&~1]; 237 zTerm = &zIn[pMem->n&~1];
238 while( zIn<zTerm ){ 238 while( zIn<zTerm ){
239 temp = *zIn; 239 temp = *zIn;
240 *zIn = *(zIn+1); 240 *zIn = *(zIn+1);
241 zIn++; 241 zIn++;
242 *zIn++ = temp; 242 *zIn++ = temp;
243 } 243 }
244 pMem->enc = desiredEnc; 244 pMem->enc = desiredEnc;
(...skipping 21 matching lines...) Expand all
266 /* Set zIn to point at the start of the input buffer and zTerm to point 1 266 /* Set zIn to point at the start of the input buffer and zTerm to point 1
267 ** byte past the end. 267 ** byte past the end.
268 ** 268 **
269 ** Variable zOut is set to point at the output buffer, space obtained 269 ** Variable zOut is set to point at the output buffer, space obtained
270 ** from sqlite3_malloc(). 270 ** from sqlite3_malloc().
271 */ 271 */
272 zIn = (u8*)pMem->z; 272 zIn = (u8*)pMem->z;
273 zTerm = &zIn[pMem->n]; 273 zTerm = &zIn[pMem->n];
274 zOut = sqlite3DbMallocRaw(pMem->db, len); 274 zOut = sqlite3DbMallocRaw(pMem->db, len);
275 if( !zOut ){ 275 if( !zOut ){
276 return SQLITE_NOMEM; 276 return SQLITE_NOMEM_BKPT;
277 } 277 }
278 z = zOut; 278 z = zOut;
279 279
280 if( pMem->enc==SQLITE_UTF8 ){ 280 if( pMem->enc==SQLITE_UTF8 ){
281 if( desiredEnc==SQLITE_UTF16LE ){ 281 if( desiredEnc==SQLITE_UTF16LE ){
282 /* UTF-8 -> UTF-16 Little-endian */ 282 /* UTF-8 -> UTF-16 Little-endian */
283 while( zIn<zTerm ){ 283 while( zIn<zTerm ){
284 READ_UTF8(zIn, zTerm, c); 284 READ_UTF8(zIn, zTerm, c);
285 WRITE_UTF16LE(z, c); 285 WRITE_UTF16LE(z, c);
286 } 286 }
(...skipping 22 matching lines...) Expand all
309 WRITE_UTF8(z, c); 309 WRITE_UTF8(z, c);
310 } 310 }
311 } 311 }
312 pMem->n = (int)(z - zOut); 312 pMem->n = (int)(z - zOut);
313 } 313 }
314 *z = 0; 314 *z = 0;
315 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len ); 315 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
316 316
317 c = pMem->flags; 317 c = pMem->flags;
318 sqlite3VdbeMemRelease(pMem); 318 sqlite3VdbeMemRelease(pMem);
319 pMem->flags = MEM_Str|MEM_Term|(c&MEM_AffMask); 319 pMem->flags = MEM_Str|MEM_Term|(c&(MEM_AffMask|MEM_Subtype));
320 pMem->enc = desiredEnc; 320 pMem->enc = desiredEnc;
321 pMem->z = (char*)zOut; 321 pMem->z = (char*)zOut;
322 pMem->zMalloc = pMem->z; 322 pMem->zMalloc = pMem->z;
323 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z); 323 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
324 324
325 translate_out: 325 translate_out:
326 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG) 326 #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
327 { 327 {
328 char zBuf[100]; 328 char zBuf[100];
329 sqlite3VdbeMemPrettyPrint(pMem, zBuf); 329 sqlite3VdbeMemPrettyPrint(pMem, zBuf);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 assert( n>0 && n<=4 ); 521 assert( n>0 && n<=4 );
522 z[0] = 0; 522 z[0] = 0;
523 z = zBuf; 523 z = zBuf;
524 READ_UTF16BE(z, 1, c); 524 READ_UTF16BE(z, 1, c);
525 assert( c==i ); 525 assert( c==i );
526 assert( (z-zBuf)==n ); 526 assert( (z-zBuf)==n );
527 } 527 }
528 } 528 }
529 #endif /* SQLITE_TEST */ 529 #endif /* SQLITE_TEST */
530 #endif /* SQLITE_OMIT_UTF16 */ 530 #endif /* SQLITE_OMIT_UTF16 */
OLDNEW
« no previous file with comments | « third_party/sqlite/src/src/update.c ('k') | third_party/sqlite/src/src/util.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698