📄 translatorreader.java
字号:
if( m_isitalic ) { buf.append("</I>"); m_isitalic = false; } if( m_isTypedText ) { buf.append("</TT>"); m_isTypedText = false; } for( ; m_listlevel > 0; m_listlevel-- ) { buf.append( "</UL>\n" ); } for( ; m_numlistlevel > 0; m_numlistlevel-- ) { buf.append( "</OL>\n" ); } if( m_isPre ) { buf.append("</PRE>\n"); m_isPre = false; } if( m_istable ) { buf.append( "</TABLE>" ); m_istable = false; } return buf.toString(); } /** * Counts how many consecutive characters of a certain type exists on the line. * @param line String of chars to check. * @param startPos Position to start reading from. * @param char Character to check for. */ private int countChar( String line, int startPos, char c ) { int count; for( count = 0; (startPos+count < line.length()) && (line.charAt(count+startPos) == c); count++ ); return count; } /** * Returns a new String that has char c n times. */ private String repeatChar( char c, int n ) { StringBuffer sb = new StringBuffer(); for( int i = 0; i < n; i++ ) sb.append(c); return sb.toString(); } private int nextToken() throws IOException { return m_in.read(); } /** * Push back any character to the current input. Does not * push back a read EOF, though. */ private void pushBack( int c ) throws IOException { if( c != -1 ) { m_in.unread( c ); } } private String handleBackslash() throws IOException { int ch = nextToken(); if( ch == '\\' ) { int ch2 = nextToken(); if( ch2 == '\\' ) { return "<BR clear=\"all\" />"; } pushBack( ch2 ); return "<BR />"; } pushBack( ch ); return "\\"; } private String handleUnderscore() throws IOException { int ch = nextToken(); String res = "_"; if( ch == '_' ) { res = m_isbold ? "</B>" : "<B>"; m_isbold = !m_isbold; } else { pushBack( ch ); } return res; } /** * For example: italics. */ private String handleApostrophe() throws IOException { int ch = nextToken(); String res = "'"; if( ch == '\'' ) { res = m_isitalic ? "</I>" : "<I>"; m_isitalic = !m_isitalic; } else { m_in.unread( ch ); } return res; } private String handleOpenbrace() throws IOException { int ch = nextToken(); String res = "{"; if( ch == '{' ) { int ch2 = nextToken(); if( ch2 == '{' ) { res = "<PRE>"; m_isPre = true; } else { pushBack( ch2 ); res = "<TT>"; m_isTypedText = true; } } else { pushBack( ch ); } return res; } /** * Handles both }} and }}} */ private String handleClosebrace() throws IOException { String res = "}"; int ch2 = nextToken(); if( ch2 == '}' ) { int ch3 = nextToken(); if( ch3 == '}' ) { if( m_isPre ) { m_isPre = false; res = "</PRE>"; } else { res = "}}}"; } } else { pushBack( ch3 ); if( !m_isPre ) { res = "</TT>"; m_isTypedText = false; } else { pushBack( ch2 ); } } } else { pushBack( ch2 ); } return res; } private String handleDash() throws IOException { int ch = nextToken(); if( ch == '-' ) { int ch2 = nextToken(); if( ch2 == '-' ) { int ch3 = nextToken(); if( ch3 == '-' ) { // Empty away all the rest of the dashes. // Do not forget to return the first non-match back. while( (ch = nextToken()) == '-' ); pushBack(ch); return "<HR />"; } pushBack( ch3 ); } pushBack( ch2 ); } pushBack( ch ); return "-"; } private String handleHeading() throws IOException { StringBuffer buf = new StringBuffer(); int ch = nextToken(); if( ch == '!' ) { int ch2 = nextToken(); if( ch2 == '!' ) { buf.append("<H2>"); m_closeTag = "</H2>"; } else { buf.append( "<H3>" ); m_closeTag = "</H3>"; pushBack( ch2 ); } } else { buf.append( "<H4>" ); m_closeTag = "</H4>"; pushBack( ch ); } return buf.toString(); } /** * Reads the stream until the next EOL or EOF. */ private StringBuffer readUntilEOL() throws IOException { int ch; StringBuffer buf = new StringBuffer(); while( true ) { ch = nextToken(); if( ch == -1 || ch == '\n' ) break; buf.append( (char) ch ); } return buf; } private int countChars( PushbackReader in, char c ) throws IOException { int count = 0; int ch; while( (ch = in.read()) != -1 ) { if( (char)ch == c ) { count++; } else { in.unread( ch ); break; } } return count; } private String handleUnorderedList() throws IOException { StringBuffer buf = new StringBuffer(); if( m_listlevel > 0 ) { buf.append("</LI>\n"); } int numBullets = countChars( m_in, '*' ) + 1; if( numBullets > m_listlevel ) { for( ; m_listlevel < numBullets; m_listlevel++ ) buf.append("<UL>\n"); } else if( numBullets < m_listlevel ) { for( ; m_listlevel > numBullets; m_listlevel-- ) buf.append("</UL>\n"); } buf.append("<LI>"); return buf.toString(); } private String handleOrderedList() throws IOException { StringBuffer buf = new StringBuffer(); if( m_numlistlevel > 0 ) { buf.append("</LI>\n"); } int numBullets = countChars( m_in, '#' ) + 1; if( numBullets > m_numlistlevel ) { for( ; m_numlistlevel < numBullets; m_numlistlevel++ ) buf.append("<OL>\n"); } else if( numBullets < m_numlistlevel ) { for( ; m_numlistlevel > numBullets; m_numlistlevel-- ) buf.append("</OL>\n"); } buf.append("<LI>"); return buf.toString(); } private String handleDefinitionList() throws IOException { if( !m_isdefinition ) { m_isdefinition = true; m_closeTag = "</DD>\n</DL>"; return "<DL>\n<DT>"; } return ";"; } private String handleOpenbracket() throws IOException { StringBuffer sb = new StringBuffer(); int ch; boolean isPlugin = false; while( (ch = nextToken()) == '[' ) { sb.append( (char)ch ); } if( ch == '{' ) { isPlugin = true; } pushBack( ch ); if( sb.length() > 0 ) { return sb.toString(); } // // Find end of hyperlink // ch = nextToken(); while( ch != -1 ) { if( ch == ']' && (!isPlugin || sb.charAt( sb.length()-1 ) == '}' ) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -