1 package org.pileus.spades;
3 import java.util.regex.Pattern;
4 import java.util.regex.Matcher;
6 import android.util.Log;
11 private final String reMsg = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+) +)?(([^: ]+) +)?(:(.*))";
12 private final String reFrom = "([^! ]+)!";
13 private final String reTo = "(([^ :,]*)[:,] *)?(.*)";
15 private static Pattern ptMsg = null;
16 private static Pattern ptFrom = null;
17 private static Pattern ptTo = null;
20 public String line = "";
22 public String src = "";
23 public String cmd = "";
24 public String dst = "";
25 public String arg = "";
26 public String msg = "";
28 public String from = "";
29 public String to = "";
30 public String txt = "";
33 private String notnull(String string)
35 return string == null ? "" : string;
39 public Message(String line)
42 if (ptMsg == null) ptMsg = Pattern.compile(reMsg);
43 if (ptFrom == null) ptFrom = Pattern.compile(reFrom);
44 if (ptTo == null) ptTo = Pattern.compile(reTo);
46 line = line.replaceAll("\\s+", " ");
47 line = line.replaceAll("^ | $", "");
48 line = line.replaceAll("\003[0-9]*", "");
51 Matcher mrMsg = ptMsg.matcher(line);
52 if (mrMsg.matches()) {
53 this.src = notnull(mrMsg.group(2));
54 this.cmd = notnull(mrMsg.group(4));
55 this.dst = notnull(mrMsg.group(6));
56 this.arg = notnull(mrMsg.group(8));
57 this.msg = notnull(mrMsg.group(10));
60 Matcher mrFrom = ptFrom.matcher(this.src);
62 this.from = notnull(mrFrom.group(1));
64 Matcher mrTo = ptTo.matcher(this.msg);
66 this.to = notnull(mrTo.group(2));
68 if (this.to.equals(""))
69 this.txt = notnull(this.msg);
71 this.txt = notnull(mrTo.group(3));
76 Log.d("Spades", "---------------------");
77 Log.d("Spades", "line = [" + line + "]");
78 Log.d("Spades", "src = " + this.src);
79 Log.d("Spades", "cmd = " + this.cmd);
80 Log.d("Spades", "dst = " + this.dst);
81 Log.d("Spades", "arg = " + this.arg);
82 Log.d("Spades", "msg = " + this.msg);
83 Log.d("Spades", "from = " + this.from);
84 Log.d("Spades", "to = " + this.to);
85 Log.d("Spades", "txt = " + this.txt);
86 Log.d("Spades", "---------------------");