Permalink
Browse files

simplify, no need for substitution here

  • Loading branch information...
1 parent c76c97a commit adfcdd8d83ca5aad0afdf32a0497c4038ea832b3 tommyrot committed May 31, 2011
Showing with 36 additions and 41 deletions.
  1. +8 −9 parser_eggdrop.class.php
  2. +7 −8 parser_irssi.class.php
  3. +7 −8 parser_mirc6.class.php
  4. +7 −8 parser_muh2.class.php
  5. +7 −8 parser_supybot.class.php
View
@@ -39,8 +39,7 @@
* - normalize_line() scrubs all lines before passing them on to parse_line().
* - Given that nicks can't contain "<", ">" or ":" the order of the regular expressions below is irrelevant (current order aims for best performance).
* - The most common channel prefixes are "#&!+" and the most common nick prefixes are "~&@%+!*".
- * - If there are multiple nicks we want to catch in our regular expression match we name the "performing" nick "nick1" and the "undergoing" nick "nick2".
- * - Some converted mIRC logs do include "!" in "mode" and "topic" lines while there is no host.
+ * - Some converted mIRC logs do include "!" in "mode" and "topic" lines while there is no host. Legacy feature.
* - In certain cases $matches[] won't contain index items if these optionally appear at the end of a line. We use empty() to check whether an index is both set and has a value.
*/
final class parser_eggdrop extends parser
@@ -94,18 +93,18 @@ protected function parse_line($line)
/**
* "Action" and "slap" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] Action: (?<line>(?<nick1>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick2>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] Action: (?<line>(?<nick_performing>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick_undergoing>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
if (!empty($matches['slap'])) {
- $this->set_slap($this->date.' '.$matches['time'], $matches['nick1'], (!empty($matches['nick2']) ? $matches['nick2'] : null));
+ $this->set_slap($this->date.' '.$matches['time'], $matches['nick_performing'], (!empty($matches['nick_undergoing']) ? $matches['nick_undergoing'] : null));
}
- $this->set_action($this->date.' '.$matches['time'], $matches['nick1'], $matches['line']);
+ $this->set_action($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['line']);
/**
* "Nickchange" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] Nick change: (?<nick1>\S+) -> (?<nick2>\S+)$/', $line, $matches)) {
- $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2']);
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] Nick change: (?<nick_performing>\S+) -> (?<nick_undergoing>\S+)$/', $line, $matches)) {
+ $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing']);
/**
* "Part" lines.
@@ -122,8 +121,8 @@ protected function parse_line($line)
/**
* "Kick" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<line>(?<nick2>\S+) kicked from [#&!+]\S+ by (?<nick1>\S+):( .+)?)$/', $line, $matches)) {
- $this->set_kick($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2'], $matches['line']);
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<line>(?<nick_undergoing>\S+) kicked from [#&!+]\S+ by (?<nick_performing>\S+):( .+)?)$/', $line, $matches)) {
+ $this->set_kick($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing'], $matches['line']);
/**
* Eggdrop logs repeated lines (case insensitive matches) in the format: "Last message repeated NUM time(s).".
View
@@ -40,7 +40,6 @@
* - The order of the regular expressions below is irrelevant (current order aims for best performance).
* - We have to be mindful that nicks can contain "[" and "]".
* - The most common channel prefixes are "#&!+" and the most common nick prefixes are "~&@%+!*".
- * - If there are multiple nicks we want to catch in our regular expression match we name the "performing" nick "nick1" and the "undergoing" nick "nick2".
* - Irssi may log multiple "performing" nicks separated by commas. We use only the first one.
* - In certain cases $matches[] won't contain index items if these optionally appear at the end of a line. We use empty() to check whether an index is both set and has a value.
*/
@@ -90,18 +89,18 @@ protected function parse_line($line)
/**
* "Action" and "slap" lines.
*/
- } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) \* (?<line>(?<nick1>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick2>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
+ } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) \* (?<line>(?<nick_performing>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick_undergoing>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
if (!empty($matches['slap'])) {
- $this->set_slap($this->date.' '.$matches['time'], $matches['nick1'], (!empty($matches['nick2']) ? $matches['nick2'] : null));
+ $this->set_slap($this->date.' '.$matches['time'], $matches['nick_performing'], (!empty($matches['nick_undergoing']) ? $matches['nick_undergoing'] : null));
}
- $this->set_action($this->date.' '.$matches['time'], $matches['nick1'], $matches['line']);
+ $this->set_action($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['line']);
/**
* "Nickchange" lines.
*/
- } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick1>\S+) is now known as (?<nick2>\S+)$/', $line, $matches)) {
- $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2']);
+ } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick_performing>\S+) is now known as (?<nick_undergoing>\S+)$/', $line, $matches)) {
+ $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing']);
/**
* "Part" lines.
@@ -118,8 +117,8 @@ protected function parse_line($line)
/**
* "Kick" lines.
*/
- } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<line>(?<nick2>\S+) was kicked from [#&!+]\S+ by (?<nick1>\S+) \[.*\])$/', $line, $matches)) {
- $this->set_kick($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2'], $matches['line']);
+ } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<line>(?<nick_undergoing>\S+) was kicked from [#&!+]\S+ by (?<nick_performing>\S+) \[.*\])$/', $line, $matches)) {
+ $this->set_kick($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing'], $matches['line']);
/**
* Skip everything else.
View
@@ -40,7 +40,6 @@
* - There is a little workaround script available referred to as "mIRC6hack". It's on the wiki.
* - Given our handling of "action" lines (and lack thereof) the order of the regular expressions below is irrelevant (current order aims for best performance).
* - The most common channel prefixes are "#&!+" and the most common nick prefixes are "~&@%+!*".
- * - If there are multiple nicks we want to catch in our regular expression match we name the "performing" nick "nick1" and the "undergoing" nick "nick2".
* - In certain cases $matches[] won't contain index items if these optionally appear at the end of a line. We use empty() to check whether an index is both set and has a value.
*/
final class parser_mirc6 extends parser
@@ -89,18 +88,18 @@ protected function parse_line($line)
/**
* "Action" and "slap" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\* [~&@%+!*]?(?<line>(?<nick1>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick2>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\* [~&@%+!*]?(?<line>(?<nick_performing>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick_undergoing>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
if (!empty($matches['slap'])) {
- $this->set_slap($this->date.' '.$matches['time'], $matches['nick1'], (!empty($matches['nick2']) ? $matches['nick2'] : null));
+ $this->set_slap($this->date.' '.$matches['time'], $matches['nick_performing'], (!empty($matches['nick_undergoing']) ? $matches['nick_undergoing'] : null));
}
- $this->set_action($this->date.' '.$matches['time'], $matches['nick1'], $matches['line']);
+ $this->set_action($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['line']);
/**
* "Nickchange" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick1>\S+) is now known as (?<nick2>\S+)$/', $line, $matches)) {
- $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2']);
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick_performing>\S+) is now known as (?<nick_undergoing>\S+)$/', $line, $matches)) {
+ $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing']);
/**
* "Part" lines.
@@ -119,8 +118,8 @@ protected function parse_line($line)
/**
* "Kick" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<line>(?<nick2>\S+) was kicked by (?<nick1>\S+) \(.*\))$/', $line, $matches)) {
- $this->set_kick($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2'], $matches['line']);
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<line>(?<nick_undergoing>\S+) was kicked by (?<nick_performing>\S+) \(.*\))$/', $line, $matches)) {
+ $this->set_kick($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing'], $matches['line']);
/**
* Skip everything else.
View
@@ -37,7 +37,6 @@
* Notes:
* - normalize_line() scrubs all lines before passing them on to parse_line().
* - Given that nicks can't contain ":" the order of the regular expressions below is irrelevant (current order aims for best performance).
- * - If there are multiple nicks we want to catch in our regular expression match we name the "performing" nick "nick1" and the "undergoing" nick "nick2".
* - In certain cases $matches[] won't contain index items if these optionally appear at the end of a line. We use empty() to check whether an index item is both set and has a value.
*/
final class parser_muh2 extends parser
@@ -86,18 +85,18 @@ protected function parse_line($line)
/**
* "Action" and "slap" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<line>(?<nick1>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick2>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<line>(?<nick_performing>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick_undergoing>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
if (!empty($matches['slap'])) {
- $this->set_slap($this->date.' '.$matches['time'], $matches['nick1'], (!empty($matches['nick2']) ? $matches['nick2'] : null));
+ $this->set_slap($this->date.' '.$matches['time'], $matches['nick_performing'], (!empty($matches['nick_undergoing']) ? $matches['nick_undergoing'] : null));
}
- $this->set_action($this->date.' '.$matches['time'], $matches['nick1'], $matches['line']);
+ $this->set_action($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['line']);
/**
* "Nickchange" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<nick1>\S+) is now known as (?<nick2>\S+)$/', $line, $matches)) {
- $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2']);
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<nick_performing>\S+) is now known as (?<nick_undergoing>\S+)$/', $line, $matches)) {
+ $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing']);
/**
* "Part" lines.
@@ -116,8 +115,8 @@ protected function parse_line($line)
/**
* "Kick" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<line>(?<nick2>\S+) was kicked by (?<nick1>\S+) \(.*\))$/', $line, $matches)) {
- $this->set_kick($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2'], $matches['line']);
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* (?<line>(?<nick_undergoing>\S+) was kicked by (?<nick_performing>\S+) \(.*\))$/', $line, $matches)) {
+ $this->set_kick($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing'], $matches['line']);
/**
* Skip everything else.
View
@@ -38,7 +38,6 @@
* - normalize_line() scrubs all lines before passing them on to parse_line().
* - The order of the regular expressions below is irrelevant (current order aims for best performance).
* - The most common channel prefixes are "#&!+".
- * - If there are multiple nicks we want to catch in our regular expression match we name the "performing" nick "nick1" and the "undergoing" nick "nick2".
* - In certain cases $matches[] won't contain index items if these optionally appear at the end of a line. We use empty() to check whether an index is both set and has a value.
*/
final class parser_supybot extends parser
@@ -87,18 +86,18 @@ protected function parse_line($line)
/**
* "Action" and "slap" lines.
*/
- } elseif (preg_match('/^\d{4}-\d{2}-\d{2}T(?<time>\d{2}:\d{2}:\d{2}) \* (?<line>(?<nick1>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick2>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
+ } elseif (preg_match('/^\d{4}-\d{2}-\d{2}T(?<time>\d{2}:\d{2}:\d{2}) \* (?<line>(?<nick_performing>\S+) ((?<slap>[sS][lL][aA][pP][sS]( (?<nick_undergoing>\S+)( .+)?)?)|(.+)))$/', $line, $matches)) {
if (!empty($matches['slap'])) {
- $this->set_slap($this->date.' '.$matches['time'], $matches['nick1'], (!empty($matches['nick2']) ? $matches['nick2'] : null));
+ $this->set_slap($this->date.' '.$matches['time'], $matches['nick_performing'], (!empty($matches['nick_undergoing']) ? $matches['nick_undergoing'] : null));
}
- $this->set_action($this->date.' '.$matches['time'], $matches['nick1'], $matches['line']);
+ $this->set_action($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['line']);
/**
* "Nickchange" lines.
*/
- } elseif (preg_match('/^\d{4}-\d{2}-\d{2}T(?<time>\d{2}:\d{2}:\d{2}) \*\*\* (?<nick1>\S+) is now known as (?<nick2>\S+)$/', $line, $matches)) {
- $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2']);
+ } elseif (preg_match('/^\d{4}-\d{2}-\d{2}T(?<time>\d{2}:\d{2}:\d{2}) \*\*\* (?<nick_performing>\S+) is now known as (?<nick_undergoing>\S+)$/', $line, $matches)) {
+ $this->set_nickchange($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing']);
/**
* "Part" lines.
@@ -117,8 +116,8 @@ protected function parse_line($line)
/**
* "Kick" lines.
*/
- } elseif (preg_match('/^\d{4}-\d{2}-\d{2}T(?<time>\d{2}:\d{2}:\d{2}) \*\*\* (?<line>(?<nick2>\S+) was kicked by (?<nick1>\S+) \(.*\))$/', $line, $matches)) {
- $this->set_kick($this->date.' '.$matches['time'], $matches['nick1'], $matches['nick2'], $matches['line']);
+ } elseif (preg_match('/^\d{4}-\d{2}-\d{2}T(?<time>\d{2}:\d{2}:\d{2}) \*\*\* (?<line>(?<nick_undergoing>\S+) was kicked by (?<nick_performing>\S+) \(.*\))$/', $line, $matches)) {
+ $this->set_kick($this->date.' '.$matches['time'], $matches['nick_performing'], $matches['nick_undergoing'], $matches['line']);
/**
* Skip everything else.

0 comments on commit adfcdd8

Please sign in to comment.