| 
			
			 | 
		#1 | 
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				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?  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#2 | 
| 
			
			
			
			 Chalut o/ 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486 
				Karma: 678910 
				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 08:45 AM.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#3 | 
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				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.
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#4 | |
| 
			
			
			
			 Chalut o/ 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486 
				Karma: 678910 
				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: 
	
 Last edited by un_pogaz; 09-09-2022 at 07:49 PM.  | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#5 | |
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				Join Date: Jan 2010 
				Location: Notts, England 
				
				
				Device: Kobo Libra 2 
				
				
				 | 
	
	
	
		
		
		
		
		 Quote: 
	
  | 
|
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#6 | 
| 
			
			
			
			 Chalut o/ 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 486 
				Karma: 678910 
				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.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
![]()  | 
            
        
    
| Thread Tools | Search this Thread | 
            
  | 
    
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| How are we dealing with case-sensitive usernames? | badbob001 | Server | 1 | 07-21-2020 01:23 PM | 
| Case Sensitive Regular Expression | silentguy | Calibre | 5 | 05-11-2015 06:56 AM | 
| Case-sensitive search | john_es | Calibre | 1 | 02-18-2014 01:25 AM | 
| Debug commands not case sensitive | jmseight | Kindle Developer's Corner | 0 | 04-04-2012 12:11 AM | 
| K3 search case sensitive only? | charonme | Amazon Kindle | 1 | 01-28-2011 06:15 PM |