Permalink
Browse files

simplify a bunch of regexps and update docs

  • Loading branch information...
tommyrot
tommyrot committed May 31, 2011
1 parent b750117 commit c76c97a87b69051fea8a9e73989507262c31954e
Showing with 23 additions and 23 deletions.
  1. +6 −6 parser_eggdrop.class.php
  2. +5 −5 parser_irssi.class.php
  3. +5 −5 parser_mirc6.class.php
  4. +6 −6 parser_muh2.class.php
  5. +1 −1 parser_supybot.class.php
View
@@ -36,7 +36,7 @@
* +------------+-------------------------------------------------------+->
*
* Notes:
- * - parse_log() normalizes all lines before passing them on to parse_line().
+ * - 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".
@@ -64,19 +64,19 @@ protected function parse_line($line)
/**
* "Join" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) \(~?\S+\) joined [#&!+]\S+\.$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) \(\S+\) joined [#&!+]\S+\.$/', $line, $matches)) {
$this->set_join($this->date.' '.$matches['time'], $matches['nick']);
/**
* "Quit" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) \(~?\S+\) left irc:( .+)?$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) \(\S+\) left irc:( .+)?$/', $line, $matches)) {
$this->set_quit($this->date.' '.$matches['time'], $matches['nick']);
/**
* "Mode" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] [#&!+]\S+: mode change \'(?<modes>[-+][ov]+([-+][ov]+)?) (?<nicks>\S+( \S+)*)\' by (?<nick>\S+?)(!(~?\S+)?)?$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] [#&!+]\S+: mode change \'(?<modes>[-+][ov]+([-+][ov]+)?) (?<nicks>\S+( \S+)*)\' by (?<nick>\S+?)(!(\S+)?)?$/', $line, $matches)) {
$nicks = explode(' ', $matches['nicks']);
$modenum = 0;
@@ -110,13 +110,13 @@ protected function parse_line($line)
/**
* "Part" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) \(~?\S+\) left [#&!+]\S+( \(.*\))?\.$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) \(\S+\) left [#&!+]\S+( \(.*\))?\.$/', $line, $matches)) {
$this->set_part($this->date.' '.$matches['time'], $matches['nick']);
/**
* "Topic" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] Topic changed on [#&!+]\S+ by (?<nick>\S+?)(!(~?\S+)?)?: (?<line>.+)$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] Topic changed on [#&!+]\S+ by (?<nick>\S+?)(!(\S+)?)?: (?<line>.+)$/', $line, $matches)) {
$this->set_topic($this->date.' '.$matches['time'], $matches['nick'], $matches['line']);
/**
View
@@ -1,7 +1,7 @@
<?php
/**
- * Copyright (c) 2009-2010, Jos de Ruijter <jos@dutnie.nl>
+ * Copyright (c) 2009-2011, Jos de Ruijter <jos@dutnie.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -36,7 +36,7 @@
* +------------+-------------------------------------------------------+->
*
* Notes:
- * - parse_log() normalizes all lines before passing them on to parse_line().
+ * - 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).
* - We have to be mindful that nicks can contain "[" and "]".
* - The most common channel prefixes are "#&!+" and the most common nick prefixes are "~&@%+!*".
@@ -60,13 +60,13 @@ protected function parse_line($line)
/**
* "Join" lines.
*/
- } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick>\S+) \[~?\S+\] has joined [#&!+]\S+$/', $line, $matches)) {
+ } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick>\S+) \[\S+\] has joined [#&!+]\S+$/', $line, $matches)) {
$this->set_join($this->date.' '.$matches['time'], $matches['nick']);
/**
* "Quit" lines.
*/
- } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick>\S+) \[~?\S+\] has quit \[.*\]$/', $line, $matches)) {
+ } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick>\S+) \[\S+\] has quit \[.*\]$/', $line, $matches)) {
$this->set_quit($this->date.' '.$matches['time'], $matches['nick']);
/**
@@ -106,7 +106,7 @@ protected function parse_line($line)
/**
* "Part" lines.
*/
- } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick>\S+) \[~?\S+\] has left [#&!+]\S+ \[.*\]$/', $line, $matches)) {
+ } elseif (preg_match('/^(?<time>\d{2}:\d{2}(:\d{2})?) -!- (?<nick>\S+) \[\S+\] has left [#&!+]\S+ \[.*\]$/', $line, $matches)) {
$this->set_part($this->date.' '.$matches['time'], $matches['nick']);
/**
View
@@ -1,7 +1,7 @@
<?php
/**
- * Copyright (c) 2009-2010, Jos de Ruijter <jos@dutnie.nl>
+ * Copyright (c) 2009-2011, Jos de Ruijter <jos@dutnie.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -35,7 +35,7 @@
* +------------+-------------------------------------------------------+->
*
* Notes:
- * - parse_log() normalizes all lines before passing them on to parse_line().
+ * - normalize_line() scrubs all lines before passing them on to parse_line().
* - The way mIRC logs actions is pretty dumb, we can spoof nearly all other line types with our actions. Even non-chat messages are logged with the same syntax. For this reason we won't parse for actions.
* - 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).
@@ -59,13 +59,13 @@ protected function parse_line($line)
/**
* "Join" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick>\S+) \(~?\S+\) has joined [#&!+]\S+$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick>\S+) \(\S+\) has joined [#&!+]\S+$/', $line, $matches)) {
$this->set_join($this->date.' '.$matches['time'], $matches['nick']);
/**
* "Quit" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick>\S+) \(~?\S+\) Quit( \(.*\))?$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick>\S+) \(\S+\) Quit( \(.*\))?$/', $line, $matches)) {
$this->set_quit($this->date.' '.$matches['time'], $matches['nick']);
/**
@@ -105,7 +105,7 @@ protected function parse_line($line)
/**
* "Part" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick>\S+) \(~?\S+\) has left [#&!+]\S+( \(.*\))?$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \* (?<nick>\S+) \(\S+\) has left [#&!+]\S+( \(.*\))?$/', $line, $matches)) {
$this->set_part($this->date.' '.$matches['time'], $matches['nick']);
/**
View
@@ -1,7 +1,7 @@
<?php
/**
- * Copyright (c) 2010, Jos de Ruijter <jos@dutnie.nl>
+ * Copyright (c) 2011, Jos de Ruijter <jos@dutnie.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -35,10 +35,10 @@
* +------------+-------------------------------------------------------+->
*
* Notes:
- * - parse_log() normalizes all lines before passing them on to parse_line().
+ * - 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 is both set and has a value.
+ * - 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
{
@@ -56,13 +56,13 @@ protected function parse_line($line)
/**
* "Join" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Joins: (?<nick>\S+) \(~?\S+\)$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Joins: (?<nick>\S+) \(\S+\)$/', $line, $matches)) {
$this->set_join($this->date.' '.$matches['time'], $matches['nick']);
/**
* "Quit" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Quits: (?<nick>\S+) \(~?\S+\) \(.*\)$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Quits: (?<nick>\S+) \(\S+\) \(.*\)$/', $line, $matches)) {
$this->set_quit($this->date.' '.$matches['time'], $matches['nick']);
/**
@@ -102,7 +102,7 @@ protected function parse_line($line)
/**
* "Part" lines.
*/
- } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Parts: (?<nick>\S+) \(~?\S+\)$/', $line, $matches)) {
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] \*\*\* Parts: (?<nick>\S+) \(\S+\)$/', $line, $matches)) {
$this->set_part($this->date.' '.$matches['time'], $matches['nick']);
/**
View
@@ -35,7 +35,7 @@
* +------------+-------------------------------------------------------+->
*
* Notes:
- * - parse_log() normalizes all lines before passing them on to parse_line().
+ * - 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".

0 comments on commit c76c97a

Please sign in to comment.