Tk Source Code

Check-in [3da68c9b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix TkUtfPrev()/TkUtfNext() implementation: Surrogates were not handled correctly, and byte checks can be more efficient: No need to call Tcl_UtfPrev()/Tcl_UtfNext() twice.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rfe-6c0d7aec67
Files: files | file ages | folders
SHA1: 3da68c9bebd57b142a28d1cfdad8c29f2ec3ccdd
User & Date: jan.nijtmans 2017-06-16 14:46:37
Context
2017-07-03
11:40
merge core-8-6-branch Closed-Leaf check-in: 19f24820 user: jan.nijtmans tags: rfe-6c0d7aec67
2017-06-16
14:46
Fix TkUtfPrev()/TkUtfNext() implementation: Surrogates were not handled correctly, and byte checks can be more efficient: No need to call Tcl_UtfPrev()/Tcl_UtfNext() twice. check-in: 3da68c9b user: jan.nijtmans tags: rfe-6c0d7aec67
2017-06-08
08:30
merge core-8-6-branch check-in: ccfaa9e6 user: jan.nijtmans tags: rfe-6c0d7aec67
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tkUtil.c.

1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
const char *
TkUtfPrev(
    const char *start,
    const char *source)
{
    const char *p = Tcl_UtfPrev(start, source);

    if (((source[0]&0xFF) == 0xED) && ((source[1]&0xF0) == 0xB0)
	    && ((source[2]&0xC0) == 0x80)) {
	/* We are pointing to a low surrogate. If the previous
	 * codepoint is a high surrogate, we want that in stead. */
	const char *q = Tcl_UtfPrev(start, p);

	if (((q[0]&0xFF) == 0xED) && ((q[1]&0xF0) == 0xA0)
		&& ((q[2]&0xC0) == 0x80)) {
	    p = q;
	}
    }
    return p;
}

/*







|
|


|

|
|







1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
const char *
TkUtfPrev(
    const char *start,
    const char *source)
{
    const char *p = Tcl_UtfPrev(start, source);

    if ((p == source-3) && ((p[0]&0xFF) == 0xED)
	    && ((p[1]&0xF0) == 0xB0) && ((p[2]&0xC0) == 0x80)) {
	/* We are pointing to a low surrogate. If the previous
	 * codepoint is a high surrogate, we want that in stead. */
	const char *q = p - 3;

	if ((q >= start) && ((q[0]&0xFF) == 0xED)
		&& ((q[1]&0xF0) == 0xA0) && ((q[2]&0xC0) == 0x80)) {
	    p = q;
	}
    }
    return p;
}

/*
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395

const char *
TkUtfNext(
    const char *source)
{
    const char *p = Tcl_UtfNext(source);

    if (((source[0]&0xFF) == 0xED) && ((source[1]&0xF0) == 0xA0)
	    && ((source[2]&0xC0) == 0x80)) {
	const char *q = Tcl_UtfNext(p);

	/* We are pointing to a high surrogate. If the next
	 * codepoint is a low surrogate, we want that in stead. */
	if (((q[0]&0xFF) == 0xED) && ((q[1]&0xF0) == 0xB0)
		&& ((q[2]&0xC0) == 0x80)) {
	    p = q;
	}
    }
    return p;
}

#endif
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */







|
|
<
<
|
|
|
|
|













1367
1368
1369
1370
1371
1372
1373
1374
1375


1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393

const char *
TkUtfNext(
    const char *source)
{
    const char *p = Tcl_UtfNext(source);

    if ((p == source+3) && ((source[0]&0xFF) == 0xED)
	    && ((source[1]&0xF0) == 0xA0) && ((source[2]&0xC0) == 0x80)) {


	/* We were pointing to a high surrogate. If the next
	 * codepoint is a low surrogate, we want to advance one more. */
	if (((p[0]&0xFF) == 0xED) && ((p[1]&0xF0) == 0xB0)
		&& ((p[2]&0xC0) == 0x80)) {
	    p += 3;
	}
    }
    return p;
}

#endif
/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */