View Ticket
Not logged in
2025-07-13
08:32 Closed ticket [8cd74c5cd2]: 2-argument string toupper/tolower/totitle doesn't work as documented plus 6 other changes artifact: 4e16c285cc user: jan.nijtmans
08:30
Doc update. See [8cd74c5cd2] check-in: 038e022dbf user: jan.nijtmans tags: trunk, main
08:02
Doc update. See [8cd74c5cd2] check-in: 2b9b8fa85b user: jan.nijtmans tags: core-9-0-branch
07:51
Doc update. See [8cd74c5cd2]. Backport more doc improvements from 9.1 check-in: 29a9305656 user: jan.nijtmans tags: core-8-6-branch
2025-07-12
19:21 Ticket [8cd74c5cd2] 2-argument string toupper/tolower/totitle doesn't work as documented status still Open with 3 other changes artifact: 727af828cd user: jan.nijtmans
17:27 Ticket [8cd74c5cd2]: 3 changes artifact: 617d0f4961 user: sebres
17:26 Ticket [8cd74c5cd2]: 3 changes artifact: 6e9c512618 user: sebres
16:50 Ticket [8cd74c5cd2]: 3 changes artifact: 7e4bda18ae user: jan.nijtmans
16:48 Ticket [8cd74c5cd2]: 4 changes artifact: ee115fd65f user: jan.nijtmans
16:42
[8cd74c5cd2]: 2-argument string toupper/tolower/totitle doesn't work as documented. Either change th... Closed-Leaf check-in: 83bd3ccec5 user: jan.nijtmans tags: bug-8cd74c5cd2
16:36 New ticket [8cd74c5cd2] 2-argument string toupper/tolower/totitle doesn't work as documented. artifact: 4c5bf8f1f5 user: jan.nijtmans

Ticket UUID: 8cd74c5cd2e93ad82b6913847a08381977eaefc3
Title: 2-argument string toupper/tolower/totitle doesn't work as documented
Type: Bug Version:
Submitter: jan.nijtmans Created on: 2025-07-12 16:36:22
Subsystem: 18. Commands M-Z Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2025-07-13 08:32:24
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2025-07-13 08:32:24
Description:

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.

User Comments: jan.nijtmans added on 2025-07-13 08:32:24:

Documentation updated in all branches


jan.nijtmans added on 2025-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)


sebres added on 2025-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.

sebres added on 2025-07-12 17:26:14:
I'm also for documentation change...<br/>
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
```

jan.nijtmans added on 2025-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!