Diff
Not logged in

Differences From Artifact [d778cb9e8c]:

To Artifact [a744ed0e1f]:


585
586
587
588
589
590
591

592
593
594
595
596
597
598
599
600
601
602
603
604



605
606
607
608
609
610
611



612
613
614
615
616



617
618
619
620
621
622
623
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603


604
605
606
607
608
609
610
611


612
613
614
615
616
617


618
619
620
621
622
623
624
625
626
627







+











-
-
+
+
+





-
-
+
+
+



-
-
+
+
+








int
Tcl_NumUtfChars(
    register const char *src,	/* The UTF-8 string to measure. */
    int length)			/* The length of the string in bytes, or -1
				 * for strlen(string). */
{
    const char *next;
    register int i = 0;

    /*
     * The separate implementations are faster.
     *
     * Since this is a time-sensitive function, we also do the check for the
     * single-byte char case specially.
     */

    if (length < 0) {
	while ((*src != '\0') && (i < INT_MAX)) {
	    src = TclUtfNext(src);
	    i++;
	    next = TclUtfNext(src);
	    i += 1 + ((next - src) > 3);
	    src = next;
	}
    } else {
	register const char *endPtr = src + length - TCL_UTF_MAX;

	while (src < endPtr) {
	    src = TclUtfNext(src);
	    i++;
	    next = TclUtfNext(src);
	    i += 1 + ((next - src) > 3);
	    src = next;
	}
	endPtr += TCL_UTF_MAX;
	while ((src < endPtr) && Tcl_UtfCharComplete(src, endPtr - src)) {
	    src = TclUtfNext(src);
	    i++;
	    next = TclUtfNext(src);
	    i += 1 + ((next - src) > 3);
	    src = next;
	}
	if (src < endPtr) {
	    i += endPtr - src;
	}
    }
    return i;
}
954
955
956
957
958
959
960
961
962
963
964
965
966
967

968
969

970
971
972






973
974

975
976

977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
958
959
960
961
962
963
964





965

966


967



968
969
970
971
972
973


974


975








976
977

978
979
980
981
982
983
984







-
-
-
-
-

-
+
-
-
+
-
-
-
+
+
+
+
+
+
-
-
+
-
-
+
-
-
-
-
-
-
-
-


-







 */

const char *
Tcl_UtfAtIndex(
    register const char *src,	/* The UTF-8 string. */
    register int index)		/* The position of the desired character. */
{
#if 0
/* The Tcl 8.6 implementation */
    Tcl_UniChar ch = 0;
    int len = 0;

    while (index-- > 0) {
	len = TclUtfToUniChar(src, &ch);
        const char *next = TclUtfNext(src);
	src += len;
    }

#if TCL_UTF_MAX == 4
    if ((ch >= 0xD800) && (len < 3)) {
	/* Index points at character following high Surrogate */
	/*
	 * 4-byte sequences generate two UCS-2 code units in the
	 * UTF-16 representation, so in the current indexing scheme
	 * we need to account for an extra index (total of two).
	 */
	index -= ((next - src) > 3);
	src = TclUtfToUniChar(src, &ch);
    }

#endif
    return src;
	src = next;
#else
/* The Tcl 8.5 implementation */
    while (index > 0) {
        index--;
        src = TclUtfNext(src);	/* NOTE: counts each valid byte sequence
				 * as one character, maybe including those
				 * that will get stored as two UCS-2 units
				 * in the UTF-16 encoding. */
    }
    return src;
#endif
}

/*
 *---------------------------------------------------------------------------
 *
 * Tcl_UtfBackslash --
 *