Converted to Java regex library.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@1255 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2003-10-10 21:30:42 +00:00
parent c47de6aa1d
commit c99f2b2499
2 changed files with 22 additions and 17 deletions
@@ -1,5 +1,5 @@
// //
// $Id: CDParanoiaRipper.java,v 1.7 2003/10/10 21:25:46 mdb Exp $ // $Id: CDParanoiaRipper.java,v 1.8 2003/10/10 21:30:42 mdb Exp $
package robodj.convert; package robodj.convert;
@@ -24,7 +24,8 @@ public class CDParanoiaRipper implements Ripper
// 1. 17980 [03:59.55] 0 [00:00.00] no no 2 // 1. 17980 [03:59.55] 0 [00:00.00] no no 2
Pattern regex; Pattern regex;
try { try {
regex = Pattern.compile("^\\s*\\d+\\.\\s+(\\d+)\\s\\[\\S*\\]\\s+(\\d+)"); regex = Pattern.compile(
"^\\s*\\d+\\.\\s+(\\d+)\\s\\[\\S*\\]\\s+(\\d+)");
} catch (PatternSyntaxException pse) { } catch (PatternSyntaxException pse) {
throw new ConvertException("Can't compile regexp?! " + pse); throw new ConvertException("Can't compile regexp?! " + pse);
} }
@@ -56,7 +57,7 @@ public class CDParanoiaRipper implements Ripper
input.append(inline).append("\n"); input.append(inline).append("\n");
// see if we match our regular expression // see if we match our regular expression
Matcher match = regex.match(inline); Matcher match = regex.matcher(inline);
if (match.matches()) { if (match.matches()) {
flist.add(inline.substring(match.start(0), match.end(0))); flist.add(inline.substring(match.start(0), match.end(0)));
flist.add(inline.substring(match.start(1), match.end(1))); flist.add(inline.substring(match.start(1), match.end(1)));
@@ -150,15 +151,15 @@ public class CDParanoiaRipper implements Ripper
} }
// parse the output // parse the output
Matcher match = regex.match(out); Matcher match = regex.matcher(out);
if (match.matches()) { if (match.matches()) {
String action = out.substring(match.start(0), match.end(0)); String action = out.substring(match.start(0), match.end(0));
long offset = -1L; long offset = -1L;
try { try {
String ostr = out.substring(match.start(1), match.end(1)); offset = Long.parseLong(
offset = Long.parseLong(ostr); out.substring(match.start(1), match.end(1)));
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
// System.err.println("Malformed position info: " + out); // System.err.println("Malformed pos. info: " + out);
continue; continue;
} }
@@ -1,12 +1,14 @@
// //
// $Id: LameEncoder.java,v 1.2 2003/10/10 19:33:16 mdb Exp $ // $Id: LameEncoder.java,v 1.3 2003/10/10 21:30:42 mdb Exp $
package robodj.convert; package robodj.convert;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import gnu.regexp.*; import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.regex.PatternSyntaxException;
/** /**
* An encoder implementation that uses LAME to do it's job. * An encoder implementation that uses LAME to do it's job.
@@ -24,13 +26,13 @@ public class LameEncoder implements Encoder
cmd.append(" ").append(dest); // add output file name cmd.append(" ").append(dest); // add output file name
// we'll need this for later // we'll need this for later
RE regex; Pattern regex;
try { try {
// a line of input looks like this // a line of input looks like this
// 0/1273 ( 0%)| 0:00/ 0:00... // 0/1273 ( 0%)| 0:00/ 0:00...
regex = new RE("^\\s*(\\d+)/(\\d+)\\s*\\(.*"); regex = Pattern.compile("^\\s*(\\d+)/(\\d+)\\s*\\(.*");
} catch (REException ree) { } catch (PatternSyntaxException pse) {
throw new ConvertException("Can't compile regexp?! " + ree); throw new ConvertException("Can't compile regexp?! " + pse);
} }
try { try {
@@ -53,12 +55,14 @@ public class LameEncoder implements Encoder
} }
// parse the output // parse the output
REMatch match = regex.getMatch(out); Matcher match = regex.matcher(out);
if (match != null) { if (match.matches()) {
int offset = -1, total = -1; int offset = -1, total = -1;
try { try {
offset = Integer.parseInt(match.toString(1)); offset = Integer.parseInt(
total = Integer.parseInt(match.toString(2)); out.substring(match.start(0), match.end(0)));
total = Integer.parseInt(
out.substring(match.start(1), match.end(1)));
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
System.err.println("Malformed position info: " + out); System.err.println("Malformed position info: " + out);
continue; continue;