Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add parser support for felixge/nodelog

  • Loading branch information...
commit fd8e2b265331a6e76e408f2a2e65c140f6dbee98 1 parent 4db6b79
@tommyrot authored
Showing with 69 additions and 0 deletions.
  1. +69 −0 parser_nodelog.php
View
69 parser_nodelog.php
@@ -0,0 +1,69 @@
+<?php
+
+/**
+ * Copyright (c) 2012, 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
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * Parse instructions for the nodelog logfile format.
+ *
+ * +------------+-------------------------------------------------------+->
+ * | Line | Format | Notes
+ * +------------+-------------------------------------------------------+->
+ * | Normal | NICK: MSG | Skip empty lines.
+ * | Join | NICK has joined the channel |
+ * | Part | NICK has left the channel |
+ * +------------+-------------------------------------------------------+->
+ *
+ * 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).
+ * - Booooring...
+ */
+final class parser_nodelog extends parser
+{
+ /**
+ * Parse a line for various chat data.
+ */
+ protected function parse_line($line)
+ {
+ /**
+ * "Normal" lines.
+ */
+ if (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+): (?<line>.+)$/', $line, $matches)) {
+ $this->set_normal($this->date.' '.$matches['time'], $matches['nick'], $matches['line']);
+
+ /**
+ * "Join" lines.
+ */
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) has joined the channel$/', $line, $matches)) {
+ $this->set_join($this->date.' '.$matches['time'], $matches['nick']);
+
+ /**
+ * "Part" lines.
+ */
+ } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) has left the channel$/', $line, $matches)) {
+ $this->set_part($this->date.' '.$matches['time'], $matches['nick']);
+
+ /**
+ * Skip everything else.
+ */
+ } elseif ($line != '') {
+ $this->output('debug', 'parse_line(): skipping line '.$this->linenum.': \''.$line.'\'');
+ }
+ }
+}
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.