⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 translatorreader.java

📁 我想下载一个东西
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            {                break;            }            sb.append( (char) ch );            ch = nextToken();        }        if( ch == -1 )        {            log.info("Warning: unterminated link detected!");            return sb.toString();        }        return handleHyperlinks( sb.toString() );    }    private String handleBar( boolean newLine )        throws IOException    {        StringBuffer sb = new StringBuffer();        if( !m_istable && !newLine )        {            return "|";        }        if( newLine )        {            if( !m_istable )            {                sb.append("<TABLE CLASS=\"wikitable\" BORDER=\"1\">\n");                m_istable = true;            }            sb.append("<TR>");            m_closeTag = "</TD></TR>";        }                int ch = nextToken();        if( ch == '|' )        {            if( !newLine )             {                sb.append("</TH>");            }            sb.append("<TH>");            m_closeTag = "</TH></TR>";        }        else        {            if( !newLine )             {                sb.append("</TD>");            }            sb.append("<TD>");            pushBack( ch );        }        return sb.toString();    }    /**     *  Generic escape of next character or entity.     */    private String handleTilde()        throws IOException    {        int ch = nextToken();        if( ch == '|' )            return "|";        if( Character.isUpperCase( (char) ch ) )        {            return String.valueOf( (char)ch );        }        // No escape.        pushBack( ch );        return "~";    }    private void fillBuffer()        throws IOException    {        StringBuffer buf = new StringBuffer();        StringBuffer word = null;        int previousCh = -2;        int start = 0;	        boolean quitReading = false;        boolean newLine     = true; // FIXME: not true if reading starts in middle of buffer        while(!quitReading)        {            int ch = nextToken();            String s = null;            //            //  Check if we're actually ending the preformatted mode.            //  We still must do an entity transformation here.            //            if( m_isPre )            {                if( ch == '}' )                {                    buf.append( handleClosebrace() );                }                else if( ch == '<' )                {                    buf.append("&lt;");                }                else if( ch == '>' )                {                    buf.append("&gt;");                }                else if( ch == -1 )                {                    quitReading = true;                }                else                 {                    buf.append( (char)ch );                }                continue;            }            //            //  CamelCase detection, a non-trivial endeavour.            //  We keep track of all white-space separated entities, which we            //  hereby refer to as "words".  We then check for an existence            //  of a CamelCase format text string inside the "word", and            //  if one exists, we replace it with a proper link.            //                        if( m_camelCaseLinks )            {                // Quick parse of start of a word boundary.                if( word == null &&                                        (Character.isWhitespace( (char)previousCh ) ||                     WORD_SEPARATORS.indexOf( (char)previousCh ) != -1 ||                     newLine ) &&                    !Character.isWhitespace( (char) ch ) )                {                    word = new StringBuffer();                }                // Are we currently tracking a word?                if( word != null )                {                    //                    //  Check for the end of the word.                    //                    if( Character.isWhitespace( (char)ch ) ||                         ch == -1 ||                        WORD_SEPARATORS.indexOf( (char) ch ) != -1 )                    {                        String potentialLink = word.toString();                        String camelCase = checkForCamelCaseLink(potentialLink);                        if( camelCase != null )                        {                            // System.out.println("Buffer is "+buf);                            // System.out.println("  Replacing "+camelCase+" with proper link.");                            start = buf.toString().lastIndexOf( camelCase );                            buf.replace(start,                                        start+camelCase.length(),                                        makeCamelCaseLink(camelCase) );                            // System.out.println("  Resulting with "+buf);                        }                        // We've ended a word boundary, so time to reset.                        word = null;                    }                    else                    {                        // This should only be appending letters and digits.                        word.append( (char)ch );                    } // if end of word                } // if word's not null                // Always set the previous character to test for word starts.                previousCh = ch;		             } // if m_camelCaseLinks            //            //  Check if any lists need closing down.            //            if( newLine && ch != '*' && ch != ' ' && m_listlevel > 0 )            {                buf.append("</LI>\n");                for( ; m_listlevel > 0; m_listlevel-- )                {                    buf.append("</UL>\n");                }            }            if( newLine && ch != '#' && ch != ' ' && m_numlistlevel > 0 )            {                buf.append("</LI>\n");                for( ; m_numlistlevel > 0; m_numlistlevel-- )                {                    buf.append("</OL>\n");                }            }            if( newLine && ch != '|' && m_istable )            {                buf.append("</TABLE>\n");                m_istable = false;                m_closeTag = null;            }            //            //  Now, check the incoming token.            //            switch( ch )            {              case '\r':                // DOS linefeeds we forget                s = null;                break;              case '\n':                //                //  Close things like headings, etc.                //                if( m_closeTag != null )                 {                    buf.append( m_closeTag );                    m_closeTag = null;                }                m_isdefinition = false;                if( newLine )                {                    // Paragraph change.                    buf.append("<P>\n");                }                else                {                    buf.append("\n");                    newLine = true;                }                break;              case '\\':                s = handleBackslash();                break;              case '_':                s = handleUnderscore();                break;                              case '\'':                s = handleApostrophe();                break;              case '{':                s = handleOpenbrace();                break;              case '}':                s = handleClosebrace();                break;              case '-':                s = handleDash();                break;              case '!':                if( newLine )                {                    s = handleHeading();                }                else                {                    s = "!";                }                break;              case ';':                if( newLine )                {                    s = handleDefinitionList();                }                else                {                    s = ";";                }                break;              case ':':                if( m_isdefinition )                {                    s = "</DT><DD>";                    m_isdefinition = false;                }                else                {                    s = ":";                }                break;              case '[':                s = handleOpenbracket();                break;              case '*':                if( newLine )                {                    s = handleUnorderedList();                }                else                {                    s = "*";                }                break;              case '#':                if( newLine )                {                    s = handleOrderedList();                }                else                {                    s = "#";                }                break;              case '|':                s = handleBar( newLine );                break;              case '<':                s = m_allowHTML ? "<" : "&lt;";                break;              case '>':                s = m_allowHTML ? ">" : "&gt;";                break;              case '\"':                s = m_allowHTML ? "\"" : "&quot;";                break;                /*              case '&':                s = "&amp;";                break;                */              case '~':                s = handleTilde();                break;              case -1:                if( m_closeTag != null )                {                    buf.append( m_closeTag );                    m_closeTag = null;                }                quitReading = true;                break;              default:                buf.append( (char)ch );                newLine = false;                break;            }            if( s != null )            {                buf.append( s );                newLine = false;            }	 }        m_data = new StringReader( buf.toString() );    }    public int read()        throws IOException    {        int val = m_data.read();        if( val == -1 )        {            fillBuffer();            val = m_data.read();            if( val == -1 )            {                m_data = new StringReader( closeAll() );                val = m_data.read();            }        }        return val;    }    public int read( char[] buf, int off, int len )        throws IOException    {        return m_data.read( buf, off, len );    }    public boolean ready()        throws IOException    {        log.debug("ready ? "+m_data.ready() );        if(!m_data.ready())        {            fillBuffer();        }        return m_data.ready();    }    public void close()    {    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -