Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 09-07-2022, 05:20 AM   #1
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,408
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Case sensitive compare in the template language?

In this post @un_pogaz mentioned that he needed a case sensitive string compare. He solved it with a custom python template function.

This raises a question: is there a general need for this? It would be easy to add case sensitive compare operators, e.g., ==!, >!, <! etc. (the ! converts the operator to case sensitive), but if they aren't useful then why take the cognitive space for them.

Opinions?
chaley is offline   Reply With Quote
Old 09-07-2022, 07:39 AM   #2
un_pogaz
Chalut o/
un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.
 
un_pogaz's Avatar
 
Posts: 439
Karma: 145424
Join Date: Dec 2017
Device: Kobo
And a srtcase() method.
I don't know how the operator implementation works, but a buit-in method would be a nice touch.

The cases are rare, and the default behavior of Calibre does the coffee very well. If it is insensitive case, okay, fine, it works the same 90% of the time.
But sometimes, when you are the kind of person who is very rigorous on the content of the DB, is useful.
When I see that authors:"Isaac Asimov" and Calibre tells me author_sort:"ASIMOV, Isaac" is valid, No! Click "Manage authors" > set author_sort:"Asimov, Isaac". And that's when I noticed it, who knows how many others have screwed up like that (well, I have plenty of functions to check that now).
Yes, Calibre is case insensitive, so it won't change anything, but now my DB is clean.

Last edited by un_pogaz; 09-07-2022 at 07:45 AM.
un_pogaz is offline   Reply With Quote
Advert
Old 09-09-2022, 05:47 PM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,408
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Given that no one other than @un_pogaz has expressed interest in this and given that @un_pogaz has a working solution, I am not going to make the changes.
chaley is offline   Reply With Quote
Old 09-09-2022, 06:36 PM   #4
un_pogaz
Chalut o/
un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.
 
un_pogaz's Avatar
 
Posts: 439
Karma: 145424
Join Date: Dec 2017
Device: Kobo
Meh, too bad, but predictable.
For information, here is my code for the strcase function (more consistent with Calibre standards)

strcase(x, y, lt, eq, gt)
Code:
def evaluate(self, formatter, kwargs, mi, locals, x, y, lt, eq, gt):
    from calibre.utils.icu import case_sensitive_strcmp as strcmp
    v = strcmp(x, y)
    if v < 0:
        return lt
    if v == 0:
        return eq
    return gt
Quote:
strcase(x, y, lt, eq, gt) -- does a case-sensitive comparison of x and y as strings. Returns lt if x < y. Returns eq if x == y. Otherwise returns gt.
Note, I'm thinking if I commit this to Calibre. Literals operator are unnecessary for a such marginal case, but providing a build-in function would be useful, so you don't have to look up how to do it if you ever need it.

Last edited by un_pogaz; 09-09-2022 at 06:49 PM.
un_pogaz is offline   Reply With Quote
Old 09-09-2022, 07:11 PM   #5
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,408
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by un_pogaz View Post
Note, I'm thinking if I commit this to Calibre. Literals operator are unnecessary for a such marginal case, but providing a build-in function would be useful, so you don't have to look up how to do it if you ever need it.
Reasonable, but I am 99.9% certain that Kovid will require adding the documentation of the function to ".../manual/template_lang.rst" before he accepts the PR.
chaley is offline   Reply With Quote
Advert
Old 09-10-2022, 05:48 AM   #6
un_pogaz
Chalut o/
un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.un_pogaz understands the importance of being earnest.
 
un_pogaz's Avatar
 
Posts: 439
Karma: 145424
Join Date: Dec 2017
Device: Kobo
The request for the doc is reasonable
Finally, I will use strcmpcase() as a name, to avoid confusion.
Now it's about not doing anything stupid and doing it properly. It's nice to push micro bug fixes, but a documented and "official" feature... caution (especially with my crappy English). But off-topic.
Have a nice day.
un_pogaz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How are we dealing with case-sensitive usernames? badbob001 Server 1 07-21-2020 12:23 PM
Case Sensitive Regular Expression silentguy Calibre 5 05-11-2015 05:56 AM
Case-sensitive search john_es Calibre 1 02-18-2014 12:25 AM
Debug commands not case sensitive jmseight Kindle Developer's Corner 0 04-03-2012 11:11 PM
K3 search case sensitive only? charonme Amazon Kindle 1 01-28-2011 05:15 PM


All times are GMT -4. The time now is 09:09 PM.


MobileRead.com is a privately owned, operated and funded community.