Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2003-07-19
05:18 • Closed ticket [769895ffff]: Tcl_UtfPrev not as documented ? plus 7 other cha... artifact: 527a6bc074 user: dkf
05:10 • Ticket [769895ffff]: 2 changes artifact: a44dcae1ac user: dkf
2003-07-18
12:59 • Ticket [769895ffff]: 1 change artifact: 9ee9d78718 user: dgp
2003-07-17
10:08 • Ticket [769895ffff]: 6 changes artifact: a6b55502d2 user: dgp
07:24 • Ticket [769895ffff]: 4 changes artifact: 7c11e33d0f user: hobbs
2003-07-12
04:43 • Ticket [769895ffff]: 1 change artifact: 051adf18fd user: dgp
2003-07-11
21:43 • New ticket [769895ffff]. artifact: e8d9931cd9 user: dgp

Tcl_UtfPrev not as documented ?

Closed / Fixed769895ffffffffffffffffffffffffffffffffffCreated 23 years agoUpdated 23 years ago
Descriptionplain2003-07-11 21:43:11
Docs for Tcl_UtfPrev(src, start) say:

     Given src, a pointer to some location  in  a 
UTF-8  string,
     Tcl_UtfPrev  returns a pointer to the previous
UTF-8 charac-
     ter in the string.  This function will  not  back
 up  to  a
     position  before  start,  the start of the UTF-8
string.  If
     src was already at start, the return value will be
start.

The source code comments just before Tcl_UtfPrev
also say:

 *      Given a pointer to some current location in a
UTF-8 string,
 *      move backwards one character.  This works
correctly when the
 *      pointer is in the middle of a UTF-8 character.

So the claim is that the src argument can be a pointer
to a trailing byte of a multi-byte character.

However, that does not appear to be what the
routine really does.  Instead, the routine starts
a search at one byte before the src argument, and
searches backward for the beginning of a UTF8
character byte-sequence and returns that.

So, for example, 

    CONST char *word="ab\303\521";
    Tcl_UtfPrev(word+3,word);

will return word+2 (pointer to the é character in UTF8)
and not word+1 (pointer to the 'b') as I would expect.

One feature of the current Tcl_UtfPrev()
implementation is that it is currently safe
to pass in a 'src' argument, that points one
byte past the end of the allocated buffer,
which can be useful, even though it seems
counter to the documentation.

Either implementation or documentation
ought to be changed to bring them into
agreement.
dgp Ticket [769895ffff]: 1 change [History diff]2003-07-12 04:43:34
hobbsplain2003-07-17 07:24:36
Logged In: YES 
user_id=72656

I think docs should be changed.  IIRC there are uses of this 
that only Tk makes use of that have to be checked against.
dgpplain2003-07-17 10:08:13
Logged In: YES 
user_id=80530

Yes, that is the consensus.
Clarify the docs to accurately
describe existing behavior.
claiming...
dgp Ticket [769895ffff]: 1 change [History diff]2003-07-18 12:59:07
dkf Ticket [769895ffff]: 2 changes [History diff]2003-07-19 05:10:46
dkfplain2003-07-19 05:18:36
Logged In: YES 
user_id=79902

Minor tightening of Tcl_UtfNext() done at same time.
Log in (anonymous is fine) to add a comment.