|
@@ -250,35 +250,66 @@ public class IRCReader implements Closeable {
|
250
|
250
|
public ReadLine(final String line, final String... lineTokens) {
|
251
|
251
|
this.line = line;
|
252
|
252
|
|
|
253
|
+ // In the case where TSIRC and message tags are used, the TSIRC tag can appear in 1 of 2 places depending
|
|
254
|
+ // on interpretation of the spec - Either right at the start of the line, or as part of the actual message.
|
|
255
|
+ // EG:
|
|
256
|
+ // @123@@tag=value :test ing
|
|
257
|
+ // @tag=value @123@:test ing
|
|
258
|
+ //
|
|
259
|
+ // are both functionally equivalent.
|
|
260
|
+ //
|
|
261
|
+ // Look for old-style TSIRC timestamp first.
|
|
262
|
+ // Then look for message tags.
|
|
263
|
+ // Then look again for tsirc, as it may be after the message tags.
|
|
264
|
+ this.tokens = checkTSIRC(checkMessageTags(checkTSIRC(lineTokens)));
|
|
265
|
+ }
|
|
266
|
+
|
|
267
|
+ /**
|
|
268
|
+ * Look for TSIRC Timestamp.
|
|
269
|
+ *
|
|
270
|
+ * @param lineTokens Current line tokens
|
|
271
|
+ * @return The line tokens after we have removed the TSIRC Timestamp if
|
|
272
|
+ * there was one, else we return lineTokens as-is.
|
|
273
|
+ */
|
|
274
|
+ private String[] checkTSIRC(final String[] lineTokens) {
|
253
|
275
|
String[] tokens = lineTokens;
|
254
|
276
|
if (!tokens[0].isEmpty() && tokens[0].charAt(0) == '@') {
|
255
|
|
- // Look for old-style TSIRC timestamp first.
|
256
|
277
|
final int tsEnd = tokens[0].indexOf('@', 1);
|
257
|
|
- boolean hasTSIRCDate = false;
|
258
|
278
|
if (tsEnd > -1) {
|
259
|
279
|
try {
|
260
|
280
|
final long ts = Long.parseLong(tokens[0].substring(1, tsEnd));
|
261
|
281
|
tags.put("tsirc date", tokens[0].substring(1, tsEnd));
|
262
|
|
- hasTSIRCDate = true;
|
263
|
282
|
tokens[0] = tokens[0].substring(tsEnd + 1);
|
264
|
283
|
} catch (final NumberFormatException nfe) { /* Not a timestamp. */ }
|
265
|
284
|
}
|
|
285
|
+ }
|
266
|
286
|
|
267
|
|
- if (!hasTSIRCDate) {
|
268
|
|
- final String[] lineTags = tokens[0].substring(1).split(";");
|
269
|
|
- for (final String keyVal : lineTags) {
|
270
|
|
- if (!keyVal.isEmpty()) {
|
271
|
|
- final String[] keyValue = keyVal.split("=", 2);
|
272
|
|
- tags.put(keyValue[0], keyValue.length > 1 ? keyValue[1] : "");
|
273
|
|
- }
|
274
|
|
- }
|
|
287
|
+ return tokens;
|
|
288
|
+ }
|
275
|
289
|
|
276
|
|
- tokens = new String[lineTokens.length - 1];
|
277
|
|
- System.arraycopy(lineTokens, 1, tokens, 0, lineTokens.length - 1);
|
|
290
|
+ /**
|
|
291
|
+ * Look for Message-Tags
|
|
292
|
+ *
|
|
293
|
+ * @param lineTokens Current line tokens
|
|
294
|
+ * @return The line tokens after we have removed the message-tags if
|
|
295
|
+ * there was any, else we return lineTokens as-is.
|
|
296
|
+ */
|
|
297
|
+ private String[] checkMessageTags(final String[] lineTokens) {
|
|
298
|
+ String[] tokens = lineTokens;
|
|
299
|
+ if (!tokens[0].isEmpty() && tokens[0].charAt(0) == '@') {
|
|
300
|
+ final String[] lineTags = tokens[0].substring(1).split(";");
|
|
301
|
+ for (final String keyVal : lineTags) {
|
|
302
|
+ if (!keyVal.isEmpty()) {
|
|
303
|
+ final String[] keyValue = keyVal.split("=", 2);
|
|
304
|
+ tags.put(keyValue[0], keyValue.length > 1 ? keyValue[1] : "");
|
|
305
|
+ }
|
278
|
306
|
}
|
|
307
|
+
|
|
308
|
+ tokens = new String[lineTokens.length - 1];
|
|
309
|
+ System.arraycopy(lineTokens, 1, tokens, 0, lineTokens.length - 1);
|
279
|
310
|
}
|
280
|
311
|
|
281
|
|
- this.tokens = tokens;
|
|
312
|
+ return tokens;
|
282
|
313
|
}
|
283
|
314
|
|
284
|
315
|
/**
|