Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2-argument string toupper/tolower/totitle doesn't work as documented

Closed / Fixed8cd74c5cd2e93ad82b6913847a08381977eaefc3Created 1 year agoUpdated 1 year ago
Descriptionwiki2025-07-12 16:36:22
According to the documentation:
If first is specified, it refers to the first char index in the string to start modifying
The documentation doesn't specify what happens if _last_ is not specified, but this suggests that modification of the string will be done until the end (just as when neither _first_ and _last_ are specified). That's not what happens:
$ tclsh8.6
% string tolower ABC 1
AbC
Reading the documentation, I would expect "Abc" as the answer. So, either the documentation or the implementation should change.

I'm not 100% sure, but I'm leaning towards changing the documentation.

Referenced by4
  • 038e022dbfDoc update. See [8cd74c5cd2] check-in2025-07-13 08:30:48
  • 2b9b8fa85bDoc update. See [8cd74c5cd2] check-in2025-07-13 08:02:35
  • 29a9305656Doc update. See [8cd74c5cd2]. Backport more doc improvements from 9.1 check-in2025-07-13 07:51:22
  • 83bd3ccec5[8cd74c5cd2]: 2-argument string toupper/tolower/totitle doesn't work as documented. Either change the documentation, or the implementation. Both are done in this commit (but only one of them should be merged to trunk) check-in2025-07-12 16:42:09
jan.nijtmanswiki2025-07-12 16:48:19

Commit [83bd3ccec5ec1208] contains both the documentation change (which adapts the documentation to the current behavior) and the implementation change (which adapts the implementation to the current documentation.

Please review: Should "string tolower ABC 1" result in "Abc" (as it currently does) or "Abc" (as the documentation suggests)?

I couldn't find any code which uses "string tolower/toupper/totitle", specifying _first_ but not _last_. But changing the implementation is a risk. Therefore I'm leaning towards changing the documentation. But if you don't agree with that (or if you agree with that), please let me know!

jan.nijtmans Ticket [8cd74c5cd2]: 3 changes [History diff]2025-07-12 16:50:37
sebresmarkdown2025-07-12 17:26:14

I'm also for documentation change...
Just because this behaviour (first is just an index without last) is at least since 8.5 (if not earlier), so even if actual docu says something different, the code works as it works everywhere dozen years and there is no one reason to change the behaviour of tcl for the sake of documentation.

Especially because it is pretty simple to force the change case to the end, with supplying the last as end (to cause "documented" behaviour):

% string tolower ABCDE 2
ABcDE
% string tolower ABCDE 2 end
ABcde

@Jan, by the way, you wrote the same statement (result) for both variants, so here again (and a bit more clear example):

# if the code wins:
% string tolower ABCDE 2
ABcDE
  \------- only given index

# if the docu wins:
% string tolower ABCDE 2
ABcde
  \-/ ---- from given index to end
sebresmarkdown2025-07-12 17:27:53

I couldn't find any code which uses "string tolower/toupper/totitle"

Even not in our test suite? That would be worse.

jan.nijtmanswiki2025-07-12 19:21:03

> Even not in our test suite? That would be worse.

In our test suite, yes. But not anywhere else (not even in Tk)

jan.nijtmanswiki2025-07-13 08:32:24

Documentation updated in all branches

Log in (anonymous is fine) to add a comment.