utf.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. /*
  2. ** 2004 April 13
  3. **
  4. ** The author disclaims copyright to this source code. In place of
  5. ** a legal notice, here is a blessing:
  6. **
  7. ** May you do good and not evil.
  8. ** May you find forgiveness for yourself and forgive others.
  9. ** May you share freely, never taking more than you give.
  10. **
  11. *************************************************************************
  12. ** This file contains routines used to translate between UTF-8,
  13. ** UTF-16, UTF-16BE, and UTF-16LE.
  14. **
  15. ** $Id: utf.c,v 1.59 2007/10/03 08:46:45 danielk1977 Exp $
  16. **
  17. ** Notes on UTF-8:
  18. **
  19. ** Byte-0 Byte-1 Byte-2 Byte-3 Value
  20. ** 0xxxxxxx 00000000 00000000 0xxxxxxx
  21. ** 110yyyyy 10xxxxxx 00000000 00000yyy yyxxxxxx
  22. ** 1110zzzz 10yyyyyy 10xxxxxx 00000000 zzzzyyyy yyxxxxxx
  23. ** 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx 000uuuuu zzzzyyyy yyxxxxxx
  24. **
  25. **
  26. ** Notes on UTF-16: (with wwww+1==uuuuu)
  27. **
  28. ** Word-0 Word-1 Value
  29. ** 110110ww wwzzzzyy 110111yy yyxxxxxx 000uuuuu zzzzyyyy yyxxxxxx
  30. ** zzzzyyyy yyxxxxxx 00000000 zzzzyyyy yyxxxxxx
  31. **
  32. **
  33. ** BOM or Byte Order Mark:
  34. ** 0xff 0xfe little-endian utf-16 follows
  35. ** 0xfe 0xff big-endian utf-16 follows
  36. **
  37. */
  38. #include "sqliteInt.h"
  39. #include <assert.h>
  40. #include "vdbeInt.h"
  41. /*
  42. ** The following constant value is used by the SQLITE_BIGENDIAN and
  43. ** SQLITE_LITTLEENDIAN macros.
  44. */
  45. const int sqlite3one = 1;
  46. /*
  47. ** This lookup table is used to help decode the first byte of
  48. ** a multi-byte UTF8 character.
  49. */
  50. static const unsigned char sqlite3UtfTrans1[] = {
  51. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  52. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  53. 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
  54. 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
  55. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  56. 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
  57. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  58. 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x00, 0x00,
  59. };
  60. #define WRITE_UTF8(zOut, c) { \
  61. if( c<0x00080 ){ \
  62. *zOut++ = (c&0xFF); \
  63. } \
  64. else if( c<0x00800 ){ \
  65. *zOut++ = 0xC0 + ((c>>6)&0x1F); \
  66. *zOut++ = 0x80 + (c & 0x3F); \
  67. } \
  68. else if( c<0x10000 ){ \
  69. *zOut++ = 0xE0 + ((c>>12)&0x0F); \
  70. *zOut++ = 0x80 + ((c>>6) & 0x3F); \
  71. *zOut++ = 0x80 + (c & 0x3F); \
  72. }else{ \
  73. *zOut++ = 0xF0 + ((c>>18) & 0x07); \
  74. *zOut++ = 0x80 + ((c>>12) & 0x3F); \
  75. *zOut++ = 0x80 + ((c>>6) & 0x3F); \
  76. *zOut++ = 0x80 + (c & 0x3F); \
  77. } \
  78. }
  79. #define WRITE_UTF16LE(zOut, c) { \
  80. if( c<=0xFFFF ){ \
  81. *zOut++ = (c&0x00FF); \
  82. *zOut++ = ((c>>8)&0x00FF); \
  83. }else{ \
  84. *zOut++ = (((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
  85. *zOut++ = (0x00D8 + (((c-0x10000)>>18)&0x03)); \
  86. *zOut++ = (c&0x00FF); \
  87. *zOut++ = (0x00DC + ((c>>8)&0x03)); \
  88. } \
  89. }
  90. #define WRITE_UTF16BE(zOut, c) { \
  91. if( c<=0xFFFF ){ \
  92. *zOut++ = ((c>>8)&0x00FF); \
  93. *zOut++ = (c&0x00FF); \
  94. }else{ \
  95. *zOut++ = (0x00D8 + (((c-0x10000)>>18)&0x03)); \
  96. *zOut++ = (((c>>10)&0x003F) + (((c-0x10000)>>10)&0x00C0)); \
  97. *zOut++ = (0x00DC + ((c>>8)&0x03)); \
  98. *zOut++ = (c&0x00FF); \
  99. } \
  100. }
  101. #define READ_UTF16LE(zIn, c){ \
  102. c = (*zIn++); \
  103. c += ((*zIn++)<<8); \
  104. if( c>=0xD800 && c<0xE000 ){ \
  105. int c2 = (*zIn++); \
  106. c2 += ((*zIn++)<<8); \
  107. c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \
  108. if( (c & 0xFFFF0000)==0 ) c = 0xFFFD; \
  109. } \
  110. }
  111. #define READ_UTF16BE(zIn, c){ \
  112. c = ((*zIn++)<<8); \
  113. c += (*zIn++); \
  114. if( c>=0xD800 && c<0xE000 ){ \
  115. int c2 = ((*zIn++)<<8); \
  116. c2 += (*zIn++); \
  117. c = (c2&0x03FF) + ((c&0x003F)<<10) + (((c&0x03C0)+0x0040)<<10); \
  118. if( (c & 0xFFFF0000)==0 ) c = 0xFFFD; \
  119. } \
  120. }
  121. /*
  122. ** Translate a single UTF-8 character. Return the unicode value.
  123. **
  124. ** During translation, assume that the byte that zTerm points
  125. ** is a 0x00.
  126. **
  127. ** Write a pointer to the next unread byte back into *pzNext.
  128. **
  129. ** Notes On Invalid UTF-8:
  130. **
  131. ** * This routine never allows a 7-bit character (0x00 through 0x7f) to
  132. ** be encoded as a multi-byte character. Any multi-byte character that
  133. ** attempts to encode a value between 0x00 and 0x7f is rendered as 0xfffd.
  134. **
  135. ** * This routine never allows a UTF16 surrogate value to be encoded.
  136. ** If a multi-byte character attempts to encode a value between
  137. ** 0xd800 and 0xe000 then it is rendered as 0xfffd.
  138. **
  139. ** * Bytes in the range of 0x80 through 0xbf which occur as the first
  140. ** byte of a character are interpreted as single-byte characters
  141. ** and rendered as themselves even though they are technically
  142. ** invalid characters.
  143. **
  144. ** * This routine accepts an infinite number of different UTF8 encodings
  145. ** for unicode values 0x80 and greater. It do not change over-length
  146. ** encodings to 0xfffd as some systems recommend.
  147. */
  148. int sqlite3Utf8Read(
  149. const unsigned char *z, /* First byte of UTF-8 character */
  150. const unsigned char *zTerm, /* Pretend this byte is 0x00 */
  151. const unsigned char **pzNext /* Write first byte past UTF-8 char here */
  152. ){
  153. int c = *(z++);
  154. if( c>=0xc0 ){
  155. c = sqlite3UtfTrans1[c-0xc0];
  156. while( z!=zTerm && (*z & 0xc0)==0x80 ){
  157. c = (c<<6) + (0x3f & *(z++));
  158. }
  159. if( c<0x80
  160. || (c&0xFFFFF800)==0xD800
  161. || (c&0xFFFFFFFE)==0xFFFE ){ c = 0xFFFD; }
  162. }
  163. *pzNext = z;
  164. return c;
  165. }
  166. /*
  167. ** If the TRANSLATE_TRACE macro is defined, the value of each Mem is
  168. ** printed on stderr on the way into and out of sqlite3VdbeMemTranslate().
  169. */
  170. /* #define TRANSLATE_TRACE 1 */
  171. #ifndef SQLITE_OMIT_UTF16
  172. /*
  173. ** This routine transforms the internal text encoding used by pMem to
  174. ** desiredEnc. It is an error if the string is already of the desired
  175. ** encoding, or if *pMem does not contain a string value.
  176. */
  177. int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
  178. unsigned char zShort[NBFS]; /* Temporary short output buffer */
  179. int len; /* Maximum length of output string in bytes */
  180. unsigned char *zOut; /* Output buffer */
  181. unsigned char *zIn; /* Input iterator */
  182. unsigned char *zTerm; /* End of input */
  183. unsigned char *z; /* Output iterator */
  184. unsigned int c;
  185. assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
  186. assert( pMem->flags&MEM_Str );
  187. assert( pMem->enc!=desiredEnc );
  188. assert( pMem->enc!=0 );
  189. assert( pMem->n>=0 );
  190. #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
  191. {
  192. char zBuf[100];
  193. sqlite3VdbeMemPrettyPrint(pMem, zBuf);
  194. fprintf(stderr, "INPUT: %s\n", zBuf);
  195. }
  196. #endif
  197. /* If the translation is between UTF-16 little and big endian, then
  198. ** all that is required is to swap the byte order. This case is handled
  199. ** differently from the others.
  200. */
  201. if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){
  202. u8 temp;
  203. int rc;
  204. rc = sqlite3VdbeMemMakeWriteable(pMem);
  205. if( rc!=SQLITE_OK ){
  206. assert( rc==SQLITE_NOMEM );
  207. return SQLITE_NOMEM;
  208. }
  209. zIn = (u8*)pMem->z;
  210. zTerm = &zIn[pMem->n];
  211. while( zIn<zTerm ){
  212. temp = *zIn;
  213. *zIn = *(zIn+1);
  214. zIn++;
  215. *zIn++ = temp;
  216. }
  217. pMem->enc = desiredEnc;
  218. goto translate_out;
  219. }
  220. /* Set len to the maximum number of bytes required in the output buffer. */
  221. if( desiredEnc==SQLITE_UTF8 ){
  222. /* When converting from UTF-16, the maximum growth results from
  223. ** translating a 2-byte character to a 4-byte UTF-8 character.
  224. ** A single byte is required for the output string
  225. ** nul-terminator.
  226. */
  227. len = pMem->n * 2 + 1;
  228. }else{
  229. /* When converting from UTF-8 to UTF-16 the maximum growth is caused
  230. ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
  231. ** character. Two bytes are required in the output buffer for the
  232. ** nul-terminator.
  233. */
  234. len = pMem->n * 2 + 2;
  235. }
  236. /* Set zIn to point at the start of the input buffer and zTerm to point 1
  237. ** byte past the end.
  238. **
  239. ** Variable zOut is set to point at the output buffer. This may be space
  240. ** obtained from sqlite3_malloc(), or Mem.zShort, if it large enough and
  241. ** not in use, or the zShort array on the stack (see above).
  242. */
  243. zIn = (u8*)pMem->z;
  244. zTerm = &zIn[pMem->n];
  245. if( len>NBFS ){
  246. zOut = sqlite3DbMallocRaw(pMem->db, len);
  247. if( !zOut ){
  248. return SQLITE_NOMEM;
  249. }
  250. }else{
  251. zOut = zShort;
  252. }
  253. z = zOut;
  254. if( pMem->enc==SQLITE_UTF8 ){
  255. if( desiredEnc==SQLITE_UTF16LE ){
  256. /* UTF-8 -> UTF-16 Little-endian */
  257. while( zIn<zTerm ){
  258. c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn);
  259. WRITE_UTF16LE(z, c);
  260. }
  261. }else{
  262. assert( desiredEnc==SQLITE_UTF16BE );
  263. /* UTF-8 -> UTF-16 Big-endian */
  264. while( zIn<zTerm ){
  265. c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn);
  266. WRITE_UTF16BE(z, c);
  267. }
  268. }
  269. pMem->n = z - zOut;
  270. *z++ = 0;
  271. }else{
  272. assert( desiredEnc==SQLITE_UTF8 );
  273. if( pMem->enc==SQLITE_UTF16LE ){
  274. /* UTF-16 Little-endian -> UTF-8 */
  275. while( zIn<zTerm ){
  276. READ_UTF16LE(zIn, c);
  277. WRITE_UTF8(z, c);
  278. }
  279. }else{
  280. /* UTF-16 Little-endian -> UTF-8 */
  281. while( zIn<zTerm ){
  282. READ_UTF16BE(zIn, c);
  283. WRITE_UTF8(z, c);
  284. }
  285. }
  286. pMem->n = z - zOut;
  287. }
  288. *z = 0;
  289. assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
  290. sqlite3VdbeMemRelease(pMem);
  291. pMem->flags &= ~(MEM_Static|MEM_Dyn|MEM_Ephem|MEM_Short);
  292. pMem->enc = desiredEnc;
  293. if( zOut==zShort ){
  294. memcpy(pMem->zShort, zOut, len);
  295. zOut = (u8*)pMem->zShort;
  296. pMem->flags |= (MEM_Term|MEM_Short);
  297. }else{
  298. pMem->flags |= (MEM_Term|MEM_Dyn);
  299. }
  300. pMem->z = (char*)zOut;
  301. translate_out:
  302. #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG)
  303. {
  304. char zBuf[100];
  305. sqlite3VdbeMemPrettyPrint(pMem, zBuf);
  306. fprintf(stderr, "OUTPUT: %s\n", zBuf);
  307. }
  308. #endif
  309. return SQLITE_OK;
  310. }
  311. /*
  312. ** This routine checks for a byte-order mark at the beginning of the
  313. ** UTF-16 string stored in *pMem. If one is present, it is removed and
  314. ** the encoding of the Mem adjusted. This routine does not do any
  315. ** byte-swapping, it just sets Mem.enc appropriately.
  316. **
  317. ** The allocation (static, dynamic etc.) and encoding of the Mem may be
  318. ** changed by this function.
  319. */
  320. int sqlite3VdbeMemHandleBom(Mem *pMem){
  321. int rc = SQLITE_OK;
  322. u8 bom = 0;
  323. if( pMem->n<0 || pMem->n>1 ){
  324. u8 b1 = *(u8 *)pMem->z;
  325. u8 b2 = *(((u8 *)pMem->z) + 1);
  326. if( b1==0xFE && b2==0xFF ){
  327. bom = SQLITE_UTF16BE;
  328. }
  329. if( b1==0xFF && b2==0xFE ){
  330. bom = SQLITE_UTF16LE;
  331. }
  332. }
  333. if( bom ){
  334. /* This function is called as soon as a string is stored in a Mem*,
  335. ** from within sqlite3VdbeMemSetStr(). At that point it is not possible
  336. ** for the string to be stored in Mem.zShort, or for it to be stored
  337. ** in dynamic memory with no destructor.
  338. */
  339. assert( !(pMem->flags&MEM_Short) );
  340. assert( !(pMem->flags&MEM_Dyn) || pMem->xDel );
  341. if( pMem->flags & MEM_Dyn ){
  342. void (*xDel)(void*) = pMem->xDel;
  343. char *z = pMem->z;
  344. pMem->z = 0;
  345. pMem->xDel = 0;
  346. rc = sqlite3VdbeMemSetStr(pMem, &z[2], pMem->n-2, bom,
  347. SQLITE_TRANSIENT);
  348. xDel(z);
  349. }else{
  350. rc = sqlite3VdbeMemSetStr(pMem, &pMem->z[2], pMem->n-2, bom,
  351. SQLITE_TRANSIENT);
  352. }
  353. }
  354. return rc;
  355. }
  356. #endif /* SQLITE_OMIT_UTF16 */
  357. /*
  358. ** pZ is a UTF-8 encoded unicode string. If nByte is less than zero,
  359. ** return the number of unicode characters in pZ up to (but not including)
  360. ** the first 0x00 byte. If nByte is not less than zero, return the
  361. ** number of unicode characters in the first nByte of pZ (or up to
  362. ** the first 0x00, whichever comes first).
  363. */
  364. int sqlite3Utf8CharLen(const char *zIn, int nByte){
  365. int r = 0;
  366. const u8 *z = (const u8*)zIn;
  367. const u8 *zTerm;
  368. if( nByte>=0 ){
  369. zTerm = &z[nByte];
  370. }else{
  371. zTerm = (const u8*)(-1);
  372. }
  373. assert( z<=zTerm );
  374. while( *z!=0 && z<zTerm ){
  375. SQLITE_SKIP_UTF8(z);
  376. r++;
  377. }
  378. return r;
  379. }
  380. /* This test function is not currently used by the automated test-suite.
  381. ** Hence it is only available in debug builds.
  382. */
  383. #if defined(SQLITE_TEST) && defined(SQLITE_DEBUG)
  384. /*
  385. ** Translate UTF-8 to UTF-8.
  386. **
  387. ** This has the effect of making sure that the string is well-formed
  388. ** UTF-8. Miscoded characters are removed.
  389. **
  390. ** The translation is done in-place (since it is impossible for the
  391. ** correct UTF-8 encoding to be longer than a malformed encoding).
  392. */
  393. int sqlite3Utf8To8(unsigned char *zIn){
  394. unsigned char *zOut = zIn;
  395. unsigned char *zStart = zIn;
  396. unsigned char *zTerm;
  397. u32 c;
  398. while( zIn[0] ){
  399. c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn);
  400. if( c!=0xfffd ){
  401. WRITE_UTF8(zOut, c);
  402. }
  403. }
  404. *zOut = 0;
  405. return zOut - zStart;
  406. }
  407. #endif
  408. #ifndef SQLITE_OMIT_UTF16
  409. /*
  410. ** Convert a UTF-16 string in the native encoding into a UTF-8 string.
  411. ** Memory to hold the UTF-8 string is obtained from sqlite3_malloc and must
  412. ** be freed by the calling function.
  413. **
  414. ** NULL is returned if there is an allocation error.
  415. */
  416. char *sqlite3Utf16to8(sqlite3 *db, const void *z, int nByte){
  417. Mem m;
  418. memset(&m, 0, sizeof(m));
  419. m.db = db;
  420. sqlite3VdbeMemSetStr(&m, z, nByte, SQLITE_UTF16NATIVE, SQLITE_STATIC);
  421. sqlite3VdbeChangeEncoding(&m, SQLITE_UTF8);
  422. if( db->mallocFailed ){
  423. sqlite3VdbeMemRelease(&m);
  424. m.z = 0;
  425. }
  426. assert( (m.flags & MEM_Term)!=0 || db->mallocFailed );
  427. assert( (m.flags & MEM_Str)!=0 || db->mallocFailed );
  428. return (m.flags & MEM_Dyn)!=0 ? m.z : sqlite3DbStrDup(db, m.z);
  429. }
  430. /*
  431. ** pZ is a UTF-16 encoded unicode string. If nChar is less than zero,
  432. ** return the number of bytes up to (but not including), the first pair
  433. ** of consecutive 0x00 bytes in pZ. If nChar is not less than zero,
  434. ** then return the number of bytes in the first nChar unicode characters
  435. ** in pZ (or up until the first pair of 0x00 bytes, whichever comes first).
  436. */
  437. int sqlite3Utf16ByteLen(const void *zIn, int nChar){
  438. unsigned int c = 1;
  439. char const *z = zIn;
  440. int n = 0;
  441. if( SQLITE_UTF16NATIVE==SQLITE_UTF16BE ){
  442. /* Using an "if (SQLITE_UTF16NATIVE==SQLITE_UTF16BE)" construct here
  443. ** and in other parts of this file means that at one branch will
  444. ** not be covered by coverage testing on any single host. But coverage
  445. ** will be complete if the tests are run on both a little-endian and
  446. ** big-endian host. Because both the UTF16NATIVE and SQLITE_UTF16BE
  447. ** macros are constant at compile time the compiler can determine
  448. ** which branch will be followed. It is therefore assumed that no runtime
  449. ** penalty is paid for this "if" statement.
  450. */
  451. while( c && ((nChar<0) || n<nChar) ){
  452. READ_UTF16BE(z, c);
  453. n++;
  454. }
  455. }else{
  456. while( c && ((nChar<0) || n<nChar) ){
  457. READ_UTF16LE(z, c);
  458. n++;
  459. }
  460. }
  461. return (z-(char const *)zIn)-((c==0)?2:0);
  462. }
  463. #if defined(SQLITE_TEST)
  464. /*
  465. ** This routine is called from the TCL test function "translate_selftest".
  466. ** It checks that the primitives for serializing and deserializing
  467. ** characters in each encoding are inverses of each other.
  468. */
  469. void sqlite3UtfSelfTest(){
  470. unsigned int i, t;
  471. unsigned char zBuf[20];
  472. unsigned char *z;
  473. unsigned char *zTerm;
  474. int n;
  475. unsigned int c;
  476. for(i=0; i<0x00110000; i++){
  477. z = zBuf;
  478. WRITE_UTF8(z, i);
  479. n = z-zBuf;
  480. z[0] = 0;
  481. zTerm = z;
  482. z = zBuf;
  483. c = sqlite3Utf8Read(z, zTerm, (const u8**)&z);
  484. t = i;
  485. if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
  486. if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
  487. assert( c==t );
  488. assert( (z-zBuf)==n );
  489. }
  490. for(i=0; i<0x00110000; i++){
  491. if( i>=0xD800 && i<0xE000 ) continue;
  492. z = zBuf;
  493. WRITE_UTF16LE(z, i);
  494. n = z-zBuf;
  495. z[0] = 0;
  496. z = zBuf;
  497. READ_UTF16LE(z, c);
  498. assert( c==i );
  499. assert( (z-zBuf)==n );
  500. }
  501. for(i=0; i<0x00110000; i++){
  502. if( i>=0xD800 && i<0xE000 ) continue;
  503. z = zBuf;
  504. WRITE_UTF16BE(z, i);
  505. n = z-zBuf;
  506. z[0] = 0;
  507. z = zBuf;
  508. READ_UTF16BE(z, c);
  509. assert( c==i );
  510. assert( (z-zBuf)==n );
  511. }
  512. }
  513. #endif /* SQLITE_TEST */
  514. #endif /* SQLITE_OMIT_UTF16 */