Bladeren bron

Remove duplication.

pull/150/head
Shane Mc Cormack 7 jaren geleden
bovenliggende
commit
247fa0a284
1 gewijzigde bestanden met toevoegingen van 28 en 17 verwijderingen
  1. 28
    17
      irc/src/main/java/com/dmdirc/parser/irc/IRCReader.java

+ 28
- 17
irc/src/main/java/com/dmdirc/parser/irc/IRCReader.java Bestand weergeven

250
         public ReadLine(final String line, final String... lineTokens) {
250
         public ReadLine(final String line, final String... lineTokens) {
251
             this.line = line;
251
             this.line = line;
252
 
252
 
253
-            String[] tokens = lineTokens;
254
-
255
             // In the case where TSIRC and message tags are used, the TSIRC tag can appear in 1 of 2 places depending
253
             // In the case where TSIRC and message tags are used, the TSIRC tag can appear in 1 of 2 places depending
256
             // on interpretation of the spec - Either right at the start of the line, or as part of the actual message.
254
             // on interpretation of the spec - Either right at the start of the line, or as part of the actual message.
257
             // EG:
255
             // EG:
259
             // @tag=value @123@:test ing
257
             // @tag=value @123@:test ing
260
             //
258
             //
261
             // are both functionally equivalent.
259
             // are both functionally equivalent.
262
-
260
+            //
263
             // Look for old-style TSIRC timestamp first.
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) {
275
+            String[] tokens = lineTokens;
264
             if (!tokens[0].isEmpty() && tokens[0].charAt(0) == '@') {
276
             if (!tokens[0].isEmpty() && tokens[0].charAt(0) == '@') {
265
                 final int tsEnd = tokens[0].indexOf('@', 1);
277
                 final int tsEnd = tokens[0].indexOf('@', 1);
266
                 if (tsEnd > -1) {
278
                 if (tsEnd > -1) {
272
                 }
284
                 }
273
             }
285
             }
274
 
286
 
275
-            // Now look for message tags.
287
+            return tokens;
288
+        }
289
+
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;
276
             if (!tokens[0].isEmpty() && tokens[0].charAt(0) == '@') {
299
             if (!tokens[0].isEmpty() && tokens[0].charAt(0) == '@') {
277
                 final String[] lineTags = tokens[0].substring(1).split(";");
300
                 final String[] lineTags = tokens[0].substring(1).split(";");
278
                 for (final String keyVal : lineTags) {
301
                 for (final String keyVal : lineTags) {
286
                 System.arraycopy(lineTokens, 1, tokens, 0, lineTokens.length - 1);
309
                 System.arraycopy(lineTokens, 1, tokens, 0, lineTokens.length - 1);
287
             }
310
             }
288
 
311
 
289
-            // Look again for tsirc, as it may be after the message tags.
290
-            if (!tokens[0].isEmpty() && tokens[0].charAt(0) == '@') {
291
-                final int tsEnd = tokens[0].indexOf('@', 1);
292
-                if (tsEnd > -1) {
293
-                    try {
294
-                        final long ts = Long.parseLong(tokens[0].substring(1, tsEnd));
295
-                        tags.put("tsirc date", tokens[0].substring(1, tsEnd));
296
-                        tokens[0] = tokens[0].substring(tsEnd + 1);
297
-                    } catch (final NumberFormatException nfe) { /* Not a timestamp. */ }
298
-                }
299
-            }
300
-
301
-            this.tokens = tokens;
312
+            return tokens;
302
         }
313
         }
303
 
314
 
304
         /**
315
         /**

Laden…
Annuleren
Opslaan