githubashto / jzebra

Automatically exported from code.google.com/p/jzebra
0 stars 1 forks source link

Minor improvements - PrintServiceMatcher #86

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Pasting from email:

I would recommend the following improvements on PrintServiceMatcher class:

- Maybe it is best to take the patterns out of loop as they are getting 
compiled every time on findPrinter method.

// TODO:  Test logics
Pattern p1 = Pattern.compile("\\b" + printerName + "\\b", 
Pattern.CASE_INSENSITIVE);
Pattern p2 = Pattern.compile("\\b" + printerName, Pattern.CASE_INSENSITIVE);
Pattern p3 = Pattern.compile(printerName, Pattern.CASE_INSENSITIVE);

moved before 

// Search for best match by name
for (PrintService ps : printers) {

- Again on the patterns printerName is not quoted so it might cause some 
problem (or not). Maybe using Pattern.quote(printerName); would solve the 
issues with printerNames containing (-) or so. But if this is actually intended 
to allow regex coming from javascript, this suggestion is obsolete. (Also I 
have not tried it with a printer name containing regex specials so I might as 
well be just dreaming)

- It might be a good idea to stop on an exact match using break.

Best Regards,
Bahadir 

Original issue reported on code.google.com by tres.fin...@gmail.com on 24 Aug 2012 at 2:29