@@ -0,0 +1,3479 @@
+package ca.szc.keratin.core.misc;%0A%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0A%0Apublic class LineWrap%0A%7B%0A    /**%0A     * According to RFC2812, this is strictly 510 characters (as the maximum allowed for the command and its%0A     * parameters), however we'll allow less than that to provide for room for the overhead. This is a rough value and%0A     * may need to become more smaller.%0A     */%0A    public static final int MAX_IRC_LENGTH = 400;%0A%0A    /**%0A     * Wrap line to lines of the maximum IRC length. Any newline (%5Cn) characters will force a line break where they%0A     * exist.%0A     * %0A     * @param line Long line to wrap%0A     * @return List of wrapped lines containing at least one string%0A     */%0A    public static List%3CString%3E wrap( String line )%0A    %7B%0A        return wrap( line, MAX_IRC_LENGTH );%0A    %7D%0A%0A    /**%0A     * Wrap a line to lines of at most the specified length. Any newline (%5Cn) characters will force a line break where%0A     * they exist. Otherwise, line breaks will be assigned to the last whitespace character in a line. If neither of%0A     * these methods works, the line maximum length will be enforced by splitting the string at the length limit.%0A     * %0A     * @param line Long line to wrap.%0A     * @param maxLineLength The maximum length of a line to allow.%0A     * @return List of wrapped lines containing at least one line.%0A     */%0A    public static List%3CString%3E wrap( String raw, final int maxLineLength )%0A    %7B%0A        // Base case?%0A        if ( raw.length() %3C= maxLineLength )%0A        %7B%0A            // Init return list%0A            List%3CString%3E lines = new LinkedList%3CString%3E();%0A%0A            // Add the whole remainder as the first inserted line%0A            lines.add( raw );%0A%0A            return lines;%0A        %7D%0A        else%0A        %7B%0A            int endIndex = -1;%0A%0A            // %5Cn characters force a break regardless of where they are.%0A            // Search in our segment for one.%0A            endIndex = raw.substring( 0, maxLineLength ).indexOf( '%5Cn' );%0A%0A            // If no %5Cn was found, search for a whitespace character closest to the end of our segment.%0A            if ( endIndex == -1 )%0A            %7B%0A                char%5B%5D rawArray = raw.toCharArray();%0A                for ( int i = maxLineLength; i %3E 0 && endIndex == -1; i-- )%0A                %7B%0A                    if ( Character.isWhitespace( rawArray%5Bi%5D ) )%0A                    %7B%0A                        endIndex = i;%0A                    %7D%0A                %7D%0A            %7D%0A%0A            // If no intelligent split point was found, just use the max size as that point%0A            if ( endIndex == -1 )%0A            %7B%0A                endIndex = maxLineLength;%0A            %7D%0A%0A            int splitSpacing = 0;%0A%0A            /*%0A             * Remove/skip-over whitespace splitting characters. This avoids including %5Cn manual split characters, which%0A             * aren't allowed by the IRC protocol, as well as having a space at the start of each automatically wrapped%0A             * line.%0A             */%0A            if ( Character.isWhitespace( raw.charAt( endIndex ) ) )%0A            %7B%0A                splitSpacing = 1;%0A            %7D%0A%0A            String line = raw.substring( 0, endIndex );%0A%0A            // Recurse on remainder of raw%0A            List%3CString%3E lines = wrap( raw.substring( endIndex + splitSpacing ), maxLineLength );%0A%0A            // Prepend our line, so the text stays in the original order%0A            lines.add( 0, line );%0A%0A            return lines;%0A        %7D%0A    %7D%0A%7D%0A

Add line wrap class/methods, for use with message splitting.