fixed regexp match running long

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@65 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-08-10 17:22:55 +00:00
parent c60df467e7
commit 35e8d341ee
2 changed files with 50 additions and 4 deletions

View file

@ -204,8 +204,8 @@ public class SbbProvider implements NetworkProvider
+ "<td .*?class=\"date.*?>\n?(?:.., (\\d{2}\\.\\d{2}\\.\\d{2})\n?)?</td>.*?" // departureDate
+ "<td .*?class=\"time.*?>(?:(\\d{2}:\\d{2})|&nbsp;)</td>.*?" // departureTime
+ "<td .*?class=\"platform.*?>\n?\\s*(.+?)?\\s*\n?</td>.*?" // departurePosition
+ "<img src=\"/img/2/products/(\\w+?)_pic.gif\" .*? alt=\"(.*?)\".*?>.*?" // line
+ "<td .*?class=\"remarks.*?>(?:\n?(\\d+) Min\\..*?)?</td>.*?" // min
+ "<img src=\"/img/2/products/(\\w+?)_pic.gif\" .*? alt=\"(.*?)\" .*?><br />.*?" // line
+ "(?:<td .*?class=\"remarks.*?>\n?(\\d+) Min\\..*?</td>.*?)?" // min
+ "<a href=\"http://fahrplan\\.sbb\\.ch/bin/bhftafel\\.exe/dn.*?input=(\\d+)&.*?\" .*?>" // arrivalId,
+ "(.*?)</a>.*?" // arrival
+ "<td .*?class=\"date.*?>\n?(?:.., (\\d{2}\\.\\d{2}\\.\\d{2})\n?)?</td>.*?" // arrivalDate
@ -433,6 +433,7 @@ public class SbbProvider implements NetworkProvider
}
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüß]+)[\\s-]*(.*)");
private static final Pattern P_NORMALIZE_LINE_SBAHN = Pattern.compile("s\\d*");
private static String normalizeLine(final String type, final String line)
{
@ -457,13 +458,17 @@ public class SbbProvider implements NetworkProvider
return "I" + strippedLine;
if (type.equals("tha")) // Thalys
return "I" + strippedLine;
if (type.equals("rj")) // RailJet, Österreichische Bundesbahnen
return "I" + strippedLine;
if (type.equals("r"))
return "R" + strippedLine;
if (type.equals("re"))
return "R" + strippedLine;
if (type.equals("ir"))
return "R" + strippedLine;
if (type.matches("s\\d*"))
if (type.equals("d"))
return "R" + strippedLine;
if (P_NORMALIZE_LINE_SBAHN.matcher(type).matches())
return "S" + strippedLine;
if (type.equals("tra"))
return "T" + strippedLine;
@ -529,7 +534,7 @@ public class SbbProvider implements NetworkProvider
return "R" + number;
if (type.equals("IR")) // InterRegio
return "RIR" + number;
if (type.equals("D")) // D-Zug?
if (type.equals("D"))
return "RD" + number;
if (type.equals("E"))
return "RE" + number;

View file

@ -28,6 +28,47 @@ import org.junit.Test;
*/
public class SbbProviderTest
{
@Test
public void tripThatTriggeredLongRunningMatch()
{
assertFineConnectionDetails("<td headers=\"stops-0\" class=\"stop-station-icon\" valign=\"top\">\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/query.exe/dn?ld=&i=mc.023454218.1281459219&n=1&uscid=10\"><img src=\"/img/2/icon_map_location.gif\" width=\"12\" height=\"12\" border=\"0\" alt=\"Umgebungskarte: Budapest-Keleti pu.\" hspace=\"3\" style=\"vertical-align:middle;margin-right:4px;\" /></a>\n" //
+ "</td>\n" //
+ "<td headers=\"stops-0\" class=\"stop-station\">\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/bhftafel.exe/dn?seqnr=1&ident=mc.023454218.1281459219&input=5510017&boardType=dep&time=21:05\" title=\"Haltestelleninformation: Budapest-Keleti pu.\">Budapest-Keleti pu.</a></td>\n" //
+ "<td headers=\"date-0\" class=\"date\" align=\"left\">\n" //
+ "Di, 10.08.10\n" //
+ "</td>\n" //
+ "<td headers=\"time-0\" class=\"time prefix timeLeft\" align=\"left\" nowrap=\"nowrap\">ab</td><td headers=\"time-0\" class=\"time timeRight\" align=\"left\" nowrap=\"nowrap\">21:05</td><td headers=\"platform-0\" class=\"platform\" align=\"left\">\n" //
+ "</td>\n" //
+ "<td headers=\"products-0\" class=\"products last\" style=\"white-space:nowrap;\" rowspan=\"2\" valign=\"top\">\n" //
+ "<img src=\"/img/2/products/en_pic.gif\" width=\"18\" height=\"18\" alt=\"EN 462\" style=\"margin-top:2px;\"><br />\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/traininfo.exe/dn/180702/86414/270520/75026/85?seqnr=1&ident=mc.023454218.1281459219&date=10.08.10&station_evaId=5510017&station_type=dep&journeyStartIdx=0&journeyEndIdx=12&\" title=\"Fahrtinformation\">\n" //
+ "EN 462\n" //
+ "</a>\n" //
+ "</td>\n" //
+ "<td headers=\"capacity-0\" class=\"capacity last\" style=\"white-space:nowrap;\" rowspan=\"2\" valign=\"top\">\n" //
+ "<div style=\"width:65px;height:15px;line-height:15px;\">\n" //
+ "<div style=\"float:left;width:30px;height:15px;line-height:15px;\">\n" //
+ "</div>\n" //
+ "<div style=\"float:left;width:30px;height:15px;line-height:15px;margin-left:4px;\">\n" //
+ "</div>\n" //
+ "</div>\n" //
+ "</td>\n" //
+ "<td headers=\"remarks-0\" class=\"remarks last\" rowspan=\"2\" valign=\"top\">\n" //
+ "EuroNight, <img src=\"/img/2/products/attr_2_pic.gif\" width=\"16\" height=\"12\" border=\"0\" title=\"Nur 2. Klasse\" alt=\"Nur 2. Klasse\"> <img src=\"/img/2/products/attr_rr_pic.gif\" width=\"16\" height=\"12\" border=\"0\" title=\"Reservierung obligatorisch\" alt=\"Reservierung obligatorisch\"> <img src=\"/img/2/products/attr_wl_pic.gif\" width=\"16\" height=\"12\" border=\"0\" title=\"Schlafwagen\" alt=\"Schlafwagen\"> <img src=\"/img/2/products/attr_cc_pic.gif\" width=\"16\" height=\"12\" border=\"0\" title=\"Liegewagen\" alt=\"Liegewagen\"> <img src=\"/img/2/products/attr_mi_pic.gif\" width=\"16\" height=\"12\" border=\"0\" title=\"Minibar\" alt=\"Minibar\"> GP </td>\n" //
+ "<td headers=\"stops-0\" class=\"stop-station-icon last\" valign=\"top\">\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/query.exe/dn?ld=&i=mc.023454218.1281459219&n=1&uscid=11\"><img src=\"/img/2/icon_map_location.gif\" width=\"12\" height=\"12\" border=\"0\" alt=\"Umgebungskarte: M&#252;nchen Hbf\" hspace=\"3\" style=\"vertical-align:middle;margin-right:4px;\" /></a></td>\n" //
+ "<td headers=\"stops-0\" class=\"stop-station last\">\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/bhftafel.exe/dn?seqnr=1&ident=mc.023454218.1281459219&input=8020347&boardType=arr&time=06:15\" title=\"Haltestelleninformation: M&#252;nchen Hbf\">M&#252;nchen Hbf</a></td>\n" //
+ "<td headers=\"date-0\" class=\"date last\" align=\"left\">\n" //
+ "Mi, 11.08.10\n" //
+ "</td>\n" //
+ "<td headers=\"time-0\" class=\"time prefix last timeLeft\" align=\"left\" nowrap=\"nowrap\">an</td><td headers=\"time-0\" class=\"time last timeRight\" align=\"left\" nowrap=\"nowrap\">06:15</td><td headers=\"platform-0\" class=\"platform last\" align=\"left\">\n" //
+ "12 \n" //
+ "</td>\n");
}
@Test
public void tripWithoutDate()
{