diff options
author | Martin Odersky <odersky@gmail.com> | 2008-07-28 10:00:31 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2008-07-28 10:00:31 +0000 |
commit | d492b489b176a3d2a4da0d199756af86514be352 (patch) | |
tree | e5cf7bedfa037a03f0fbf1bb72564114473edef0 /src/library | |
parent | c8b3af98b9dd45a358332f60e3bc8f5b8b3c604a (diff) | |
download | scala-d492b489b176a3d2a4da0d199756af86514be352.tar.gz scala-d492b489b176a3d2a4da0d199756af86514be352.tar.bz2 scala-d492b489b176a3d2a4da0d199756af86514be352.zip |
fixed #842, #945, #83, #996, #1016, + some perf...
fixed #842, #945, #83, #996, #1016, + some performace tuning.
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/util/matching/Regex.scala | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala index 0db6372655..56c90f1073 100644 --- a/src/library/scala/util/matching/Regex.scala +++ b/src/library/scala/util/matching/Regex.scala @@ -132,41 +132,61 @@ object Regex { /** The names of the groups, or some empty sequence if one defined */ val groupNames: Seq[String] - /** The index of the first matched character */ + /** The number of subgroups in the pattern (not all of these need to match!) */ + def groupCount: Int + + /** The index of the first matched character, or -1 if nothing was matched */ def start: Int - /** The index of the first matched character in group <code>i</code> */ + /** The index of the first matched character in group <code>i</code>, + * or -1 if nothing was matched for that group */ def start(i: Int): Int - /** The index of the last matched character */ + /** The index of the last matched character, or -1 if nothing was matched */ def end: Int - /** The number of subgroups */ - def groupCount: Int - - /** The index following the last matched character in group <code>i</code> */ + /** The index following the last matched character in group <code>i</code>, + * or -1 if nothing was matched for that group */ def end(i: Int): Int - /** The matched string */ - def matched: String = source.subSequence(start, end).toString + /** The matched string, + * of <code>null</code> if nothing was matched */ + def matched: String = + if (start >= 0) source.subSequence(start, end).toString + else null - /** The matched string in group <code>i</code> */ - def group(i: Int): String = source.subSequence(start(i), end(i)).toString + /** The matched string in group <code>i</code>, + * or <code>null</code> if nothing was matched */ + def group(i: Int): String = + if (start(i) >= 0) source.subSequence(start(i), end(i)).toString + else null /** All matched subgroups, i.e. not including group(0) */ def subgroups: List[String] = (1 to groupCount).toList map group - /** The char sequence before first character of match */ - def before: java.lang.CharSequence = source.subSequence(0, start) - - /** The char sequence before first character of match in group <code>i</code> */ - def before(i: Int): java.lang.CharSequence = source.subSequence(0, start(i)) - - /** Returns char sequence after last character of match */ - def after: java.lang.CharSequence = source.subSequence(end, source.length) - - /** The char sequence after last character of match in group <code>i</code> */ - def after(i: Int): java.lang.CharSequence = source.subSequence(end(i), source.length) + /** The char sequence before first character of match, + * or <code>null</code> if nothing was matched */ + def before: java.lang.CharSequence = + if (start >= 0) source.subSequence(0, start) + else null + + /** The char sequence before first character of match in group <code>i</code>, + * or <code>null</code> if nothing was matched for that group */ + def before(i: Int): java.lang.CharSequence = + if (start(i) >= 0) source.subSequence(0, start(i)) + else null + + /** Returns char sequence after last character of match, + * or <code>null</code> if nothing was matched */ + def after: java.lang.CharSequence = + if (end >= 0) source.subSequence(end, source.length) + else null + + /** The char sequence after last character of match in group <code>i</code>, + * or <code>null</code> if nothing was matched for that group */ + def after(i: Int): java.lang.CharSequence = + if (end(i) >= 0) source.subSequence(end(i), source.length) + else null private lazy val nameToIndex: Map[String, Int] = Map() ++ ("" :: groupNames.toList).zipWithIndex |