Diff
Not logged in

Differences From Artifact [30ac31a78d]:

To Artifact [2893b6395e]:


220
221
222
223
224
225
226
227

228
229
230
231
232

233
234
235
236
237
238
239



240
241
242
243
244
245
246
220
221
222
223
224
225
226

227
228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249







-
+




-
+







+
+
+







 *
 *---------------------------------------------------------------------------
 */

#undef Tcl_UniCharToUtfDString
char *
Tcl_UniCharToUtfDString(
    const unsigned int *uniStr,	/* Unicode string to convert to UTF-8. */
    const int *uniStr,	/* Unicode string to convert to UTF-8. */
    int uniLength,		/* Length of Unicode string. */
    Tcl_DString *dsPtr)		/* UTF-8 representation of string is appended
				 * to this previously initialized DString. */
{
    const unsigned int *w, *wEnd;
    const int *w, *wEnd;
    char *p, *string;
    int oldLength;

    /*
     * UTF-8 string length in bytes will be <= Unicode string length * 4.
     */

    if (uniStr == NULL) {
	return NULL;
    }
    if (uniLength < 0) {
	uniLength = 0;
	w = uniStr;
	while (*w != '\0') {
	    uniLength++;
	    w++;
	}
256
257
258
259
260
261
262
263
264
265

266
267
268
269
270
271
272
273
274
275
276
277
278



279
280
281
282
283
284
285
259
260
261
262
263
264
265

266

267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290







-

-
+













+
+
+







	w++;
    }
    Tcl_DStringSetLength(dsPtr, oldLength + (p - string));

    return string;
}

#undef Tcl_WCharToUtfDString
char *
Tcl_WCharToUtfDString(
Tcl_Char16ToUtfDString(
    const unsigned short *uniStr,	/* Utf-16 string to convert to UTF-8. */
    int uniLength,		/* Length of Utf-16 string. */
    Tcl_DString *dsPtr)		/* UTF-8 representation of string is appended
				 * to this previously initialized DString. */
{
    const unsigned short *w, *wEnd;
    char *p, *string;
    int oldLength, len = 1;

    /*
     * UTF-8 string length in bytes will be <= Utf16 string length * 3.
     */

    if (uniStr == NULL) {
	return NULL;
    }
    if (uniLength < 0) {

	uniLength = 0;
	w = uniStr;
	while (*w != '\0') {
	    uniLength++;
	    w++;
353
354
355
356
357
358
359
360

361
362
363

364
365
366
367
368
369
370
358
359
360
361
362
363
364

365
366
367

368
369
370
371
372
373
374
375







-
+


-
+







   0x2DC, 0x2122, 0x0161, 0x203A, 0x0153,   0x9D, 0x017E, 0x0178
};

#undef Tcl_UtfToUniChar
int
Tcl_UtfToUniChar(
    register const char *src,	/* The UTF-8 string. */
    register unsigned int *chPtr)/* Filled with the unsigned int represented by
    register int *chPtr)/* Filled with the unsigned int represented by
				 * the UTF-8 string. */
{
    unsigned int byte;
    int byte;

    /*
     * Unroll 1 to 4 byte UTF-8 sequences.
     */

    byte = *((unsigned char *) src);
    if (byte < 0xC0) {
434
435
436
437
438
439
440
441
442
443

444
445
446
447
448
449
450
439
440
441
442
443
444
445

446

447
448
449
450
451
452
453
454







-

-
+







	 */
    }

    *chPtr = byte;
    return 1;
}

#undef Tcl_UtfToWChar
int
Tcl_UtfToWChar(
Tcl_UtfToChar16(
    const char *src,	/* The UTF-8 string. */
    unsigned short *chPtr)/* Filled with the unsigned short represented by
				 * the UTF-8 string. */
{
    unsigned short byte;

    /*
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
569
570

571
572
573



574
575
576
577
578
579
580
581
582
583
584
585
586
587

588
589
590
591
592
593
594
558
559
560
561
562
563
564

565
566
567
568
569
570
571
572
573

574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593

594
595
596
597
598
599
600
601







-
+








-
+



+
+
+













-
+







 * Side effects:
 *	None.
 *
 *---------------------------------------------------------------------------
 */

#undef Tcl_UtfToUniCharDString
unsigned int *
int *
Tcl_UtfToUniCharDString(
    const char *src,		/* UTF-8 string to convert to Unicode. */
    int length,			/* Length of UTF-8 string in bytes, or -1 for
				 * strlen(). */
    Tcl_DString *dsPtr)		/* Unicode representation of string is
				 * appended to this previously initialized
				 * DString. */
{
    unsigned int ch = 0, *w, *wString;
    int ch = 0, *w, *wString;
    const char *p, *end;
    int oldLength;

    if (src == NULL) {
	return NULL;
    }
    if (length < 0) {
	length = strlen(src);
    }

    /*
     * Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
     * bytes.
     */

    oldLength = Tcl_DStringLength(dsPtr);

    Tcl_DStringSetLength(dsPtr,
	    oldLength + ((length + 1) * sizeof(unsigned int)));
    wString = (unsigned int *) (Tcl_DStringValue(dsPtr) + oldLength);
    wString = (int *) (Tcl_DStringValue(dsPtr) + oldLength);

    w = wString;
    p = src;
    end = src + length - 4;
    while (p < end) {
	p += Tcl_UtfToUniChar(p, &ch);
	*w++ = ch;
605
606
607
608
609
610
611
612
613
614

615
616
617
618
619
620
621
622
623
624
625
626



627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646

647
648
649
650
651
652

653
654
655
656
657
658
659
612
613
614
615
616
617
618

619

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654

655
656
657
658
659
660

661
662
663
664
665
666
667
668







-

-
+












+
+
+



















-
+





-
+







    *w = '\0';
    Tcl_DStringSetLength(dsPtr,
	    oldLength + ((char *) w - (char *) wString));

    return wString;
}

#undef Tcl_UtfToWCharDString
unsigned short *
Tcl_UtfToWCharDString(
Tcl_UtfToChar16DString(
    const char *src,		/* UTF-8 string to convert to Unicode. */
    int length,			/* Length of UTF-8 string in bytes, or -1 for
				 * strlen(). */
    Tcl_DString *dsPtr)		/* Unicode representation of string is
				 * appended to this previously initialized
				 * DString. */
{
    unsigned short ch = 0;
    unsigned short *w, *wString;
    const char *p, *end;
    int oldLength;

    if (src == NULL) {
	return NULL;
    }
    if (length < 0) {
	length = strlen(src);
    }

    /*
     * Unicode string length in Tcl_UniChars will be <= UTF-8 string length in
     * bytes.
     */

    oldLength = Tcl_DStringLength(dsPtr);

    Tcl_DStringSetLength(dsPtr,
	    oldLength + ((length + 1) * sizeof(unsigned short)));
    wString = (unsigned short *) (Tcl_DStringValue(dsPtr) + oldLength);

    w = wString;
    p = src;
    end = src + length - 4;
    while (p < end) {
	p += Tcl_UtfToWChar(p, &ch);
	p += Tcl_UtfToChar16(p, &ch);
	*w++ = ch;
    }
    end += 4;
    while (p < end) {
	if (Tcl_UtfCharComplete(p, end-p)) {
	    p += Tcl_UtfToWChar(p, &ch);
	    p += Tcl_UtfToChar16(p, &ch);
	} else {
	    ch = UCHAR(*p++);
	}
	*w++ = ch;
    }
    *w = '\0';
    Tcl_DStringSetLength(dsPtr,