Skip to content
Newer
Older
100644 70 lines (63 sloc) 2.44 KB
fd8e2b2 @tommyrot add parser support for felixge/nodelog
authored Sep 22, 2012
1 <?php
2
3 /**
4 * Copyright (c) 2012, Jos de Ruijter <jos@dutnie.nl>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /**
20 * Parse instructions for the nodelog logfile format.
21 *
22 * +------------+-------------------------------------------------------+->
23 * | Line | Format | Notes
24 * +------------+-------------------------------------------------------+->
25 * | Normal | NICK: MSG | Skip empty lines.
26 * | Join | NICK has joined the channel |
27 * | Part | NICK has left the channel |
28 * +------------+-------------------------------------------------------+->
29 *
30 * Notes:
31 * - normalize_line() scrubs all lines before passing them on to parse_line().
32 * - Given that nicks can't contain ":" the order of the regular expressions below is irrelevant (current order aims for best performance).
33 * - Booooring...
34 */
35 final class parser_nodelog extends parser
36 {
37 /**
38 * Parse a line for various chat data.
39 */
40 protected function parse_line($line)
41 {
42 /**
43 * "Normal" lines.
44 */
45 if (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+): (?<line>.+)$/', $line, $matches)) {
46 $this->set_normal($this->date.' '.$matches['time'], $matches['nick'], $matches['line']);
47
48 /**
49 * "Join" lines.
50 */
51 } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) has joined the channel$/', $line, $matches)) {
52 $this->set_join($this->date.' '.$matches['time'], $matches['nick']);
53
54 /**
55 * "Part" lines.
56 */
57 } elseif (preg_match('/^\[(?<time>\d{2}:\d{2}(:\d{2})?)\] (?<nick>\S+) has left the channel$/', $line, $matches)) {
58 $this->set_part($this->date.' '.$matches['time'], $matches['nick']);
59
60 /**
61 * Skip everything else.
62 */
63 } elseif ($line != '') {
64 $this->output('debug', 'parse_line(): skipping line '.$this->linenum.': \''.$line.'\'');
65 }
66 }
67 }
68
69 ?>
Something went wrong with that request. Please try again.