Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-01-2013, 10:47 PM   #1
bookworm2000
Junior Member
bookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the rough
 
Posts: 7
Karma: 7220
Join Date: Dec 2012
Device: Kindle 4, Kindle for Android
Template/Regular Expression Trouble

Hi,

I'm using a custom column to work with the Kindle Collections plugin. It collects author names in three groups ("A-I", "J-Q" and "S-Z"). A fourth ("other") is reserved for authors who might call themselves something like 123foo or $bar.

The following code worked fine so far...

Code:
program:
	author_first_letter = substr(field('author_sort'), 0, 1);
	group = switch(author_first_letter,
		'[A-I]', 'A-I',
		'[J-R]', 'J-R',
		'[S-Z]', 'S-Z',
		'other');
	strcat('Authors ', group)

...until Karel Čapek came along.

His books should be found in the "A-I" collection but are listed under "other". So I expanded the regular expression to

Code:
	[A-IĀ-IJ]
That works fine in the Edit template window, the calculated Template value is "Authors A-I".

But the colums and tag browser show it under "other".

I also tried unicode:

Code:
	[A-I\u0100-\u0132]
but it's still an incorrect result.

Being both 1) new to the calibre template language and 2) a regular-expression-avoider-whenever-I-can I assume that I made a mistake... but what puzzles me is that the Template value of the Edit template window shows the expected "Authors A-I" (at least in the first case, without unicode notation).

Could this be a bug in Calibre?

Last edited by bookworm2000; 01-01-2013 at 10:54 PM. Reason: typo
bookworm2000 is offline   Reply With Quote
Old 01-02-2013, 06:31 AM   #2
chaley
"chaley", not "charley"
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: 5,893
Karma: 1216548
Join Date: Jan 2010
Location: France
Device: Many android devices
You found a strange bug in calibre that has been lurking for many months. Character classes are not processed in unicode in compiled template functions, but *are* in interpreted template functions. Functions are interpreted when using the template editor. They are compiled for performance when used in composite columns.

I have submitted a fix that should be in the next release. In the meantime you can work around the problem by changing the tweak "Compile General Program Mode templates to Python" to False.
chaley is offline   Reply With Quote
Old 01-02-2013, 08:24 AM   #3
bookworm2000
Junior Member
bookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the roughbookworm2000 is a jewel in the rough
 
Posts: 7
Karma: 7220
Join Date: Dec 2012
Device: Kindle 4, Kindle for Android
Thank you for the fast reply. That solved the problem.
bookworm2000 is offline   Reply With Quote
Reply

Tags
regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
More than 3 regular expression? james968 Conversion 1 04-04-2012 06:39 AM
Regular Expression Help Azhad Calibre 86 09-27-2011 03:37 PM
Regular Expression Help smartmart Calibre 5 10-17-2010 06:19 AM
Help!! Having trouble with regular expression Partzz Calibre 2 09-14-2010 01:32 PM
Help with the regular expression Dysonco Calibre 9 03-22-2010 11:45 PM


All times are GMT -4. The time now is 10:00 AM.


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