Browse Source

A List of Characters... AKA a String.

Change-Id: I4ee609a42962a025e022315e64d199d1a8ecf3ba
Reviewed-on: http://gerrit.dmdirc.com/2814
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.8
Chris Smith 10 years ago
parent
commit
536bec635e
1 changed files with 15 additions and 40 deletions
  1. 15
    40
      src/com/dmdirc/parser/irc/IRCParser.java

+ 15
- 40
src/com/dmdirc/parser/irc/IRCParser.java View File

@@ -102,6 +102,14 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
102 102
     static final byte MODE_SET = 2;
103 103
     /** Byte used to show that a non-boolean mode is not a list, and requires a parameter to unset (k). */
104 104
     static final byte MODE_UNSET = 4;
105
+
106
+    /**
107
+     * Default channel prefixes if none are specified by the IRCd.
108
+     *
109
+     * <p>These are the RFC 2811 specified prefixes: '#', '&amp;', '!' and '+'.
110
+     */
111
+    private static final String DEFAULT_CHAN_PREFIX = "#&!+";
112
+
105 113
     /**
106 114
      * This is what the user wants settings to be.
107 115
      * Nickname here is *not* always accurate.<br><br>
@@ -186,7 +194,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
186 194
     /** Should the lastline (where given) be appended to the "data" part of any onErrorInfo call? */
187 195
     private boolean addLastLine = false;
188 196
     /** Channel Prefixes (ie # + etc). */
189
-    private final List<Character> chanPrefix = Collections.synchronizedList(new LinkedList<Character>());
197
+    private String chanPrefix = DEFAULT_CHAN_PREFIX;
190 198
     /** Hashtable storing all known clients based on nickname (in lowercase). */
191 199
     private final Map<String, IRCClientInfo> clientList = new HashMap<String, IRCClientInfo>();
192 200
     /** Hashtable storing all known channels based on chanel name (inc prefix - in lowercase). */
@@ -705,7 +713,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
705 713
         chanModesOther.clear();
706 714
         chanModesBool.clear();
707 715
         userModes.clear();
708
-        chanPrefix.clear();
716
+        chanPrefix = DEFAULT_CHAN_PREFIX;
709 717
         // Clear output queue.
710 718
         if (out != null) {
711 719
             out.clearQueue();
@@ -1591,19 +1599,7 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1591 1599
     /** {@inheritDoc} */
1592 1600
     @Override
1593 1601
     public String getChannelPrefixes() {
1594
-        if (chanPrefix.isEmpty()) {
1595
-            return "#&";
1596
-        }
1597
-
1598
-        final StringBuilder builder = new StringBuilder(chanPrefix.size());
1599
-
1600
-        synchronized (chanPrefix) {
1601
-            for (Character prefix : chanPrefix) {
1602
-                builder.append(prefix);
1603
-            }
1604
-        }
1605
-
1606
-        return builder.toString();
1602
+        return chanPrefix;
1607 1603
     }
1608 1604
 
1609 1605
     /**
@@ -1670,25 +1666,10 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
1670 1666
      * Process CHANTYPES from 005.
1671 1667
      */
1672 1668
     protected void parseChanPrefix() {
1673
-        final String sDefaultModes = "#&";
1674
-        String modeStr;
1675
-        if (h005Info.containsKey("CHANTYPES")) {
1676
-            modeStr = h005Info.get("CHANTYPES");
1669
+        if (h005Info.containsKey("CHANTYPES") && !h005Info.get("CHANTYPES").isEmpty()) {
1670
+            chanPrefix = h005Info.get("CHANTYPES");
1677 1671
         } else {
1678
-            modeStr = sDefaultModes;
1679
-            h005Info.put("CHANTYPES", sDefaultModes);
1680
-        }
1681
-
1682
-        // resetState
1683
-        chanPrefix.clear();
1684
-
1685
-        // Boolean Mode
1686
-        for (int i = 0; i < modeStr.length(); ++i) {
1687
-            final Character cMode = modeStr.charAt(i);
1688
-            callDebugInfo(DEBUG_INFO, "Found Chan Prefix: %c", cMode);
1689
-            if (!chanPrefix.contains(cMode)) {
1690
-                chanPrefix.add(cMode);
1691
-            }
1672
+            h005Info.put("CHANTYPES", DEFAULT_CHAN_PREFIX);
1692 1673
         }
1693 1674
     }
1694 1675
 
@@ -2028,16 +2009,10 @@ public class IRCParser extends BaseParser implements SecureParser, EncodingParse
2028 2009
         if (getChannel(name) != null) {
2029 2010
             return true;
2030 2011
         }
2031
-        // Check if we know of any valid chan prefixes
2032
-        if (chanPrefix.isEmpty()) {
2033
-            // We don't. Lets check against RFC2811-Specified channel types
2034
-            final char first = name.charAt(0);
2035
-            return first == '#' || first == '&' || first == '!' || first == '+';
2036
-        }
2037 2012
         // Otherwise return true if:
2038 2013
         // Channel equals "0"
2039 2014
         // first character of the channel name is a valid channel prefix.
2040
-        return chanPrefix.contains(name.charAt(0)) || "0".equals(name);
2015
+        return chanPrefix.indexOf(name.charAt(0)) >= 0 || "0".equals(name);
2041 2016
     }
2042 2017
 
2043 2018
     /** {@inheritDoc} */

Loading…
Cancel
Save