View Single Post
Old 01-12-2026, 01:21 PM   #18
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 9,585
Karma: 6774048
Join Date: Nov 2009
Device: many
Quote:
Originally Posted by jwes View Post
Perhaps I did not explain myself clearly. It works the way I would expect for strings that contain no lowercase characters and it works for strings that have words with only initial capital or no capital letters. It does not work the way I would expect for strings that have words that are all capitalized and other words that have lower case letters.

If you change the line in titlecase.py about line 61
Code:
from:
        if all_caps:
to
        if toUpper(word) == word:
then it appears to work the way I would expect.

Not sure I follow, unless I am missing something if I make that change, how will it ignore titles already in all Uppercase?

If a title string is all uppercase, then each word of the title is all uppercased and the same thing happens as UC_INITIALS regex should return true for all words in a string that is all capitalized.

How all caps is handled is by design in the titlecase routine.

If you don't want that, then in your own replace function forcibly lowercase any strings you want to force to titlecase first. You can do that right in your own titlecase function. That is the power of python function replace.

Simply use the replace_lowercase call and store its result then assign it to the match.string in the match object passed in and then invoke the replace_titlecase.

If the titlecase.py code did not ignore things already in all caps, then it would make it hard to ignore titles already in all uppercase for a reason (ie. higher level major section titles often use all uppercase). You can control how that gets handled in your own function.

Last edited by KevinH; 01-12-2026 at 02:07 PM.
KevinH is offline   Reply With Quote