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

📄 buffer.java

📁 gcc的组建
💻 JAVA
字号:
/* Buffer.java --   Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.javax.swing.text.html.parser.support.low;/** * A string buffer that additionally holds line and absolute postion * information. * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) */public class Buffer{  public static int INITIAL_SIZE = 2048;  /**   * True if the \n symbol has been seen.   */  public boolean n_seen;  /**   * True if the \r symbol has been seen.   */  public boolean r_seen;  char[] chr = new char[ INITIAL_SIZE ];  int[] line = new int[ INITIAL_SIZE ];  int[] position = new int[ INITIAL_SIZE ];  /**   * Current line.   */  int current_line = 0;  /**   * Point to the next free position.   */  int length;  public Buffer()  {  }  public Buffer(String content)  {    for (int i = 0; i < content.length(); i++)      {        append(content.charAt(i), i);      }  }  /**   * Get the characters into array.   * @param srcBegin From, inclusive   * @param srcEnd To, exclusive.   * @param dst Into   * @param dstBegin Offset.   */  public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)  {    System.arraycopy(chr, srcBegin, dst, dstBegin, (srcEnd - srcBegin));  }  /**   * Return the sequence, used to separate lines in the document.   * @return one of \n, \r or \r\n.   */  public String getEndOfLineSequence()  {    if (r_seen && n_seen)      return "\r\n";    else if (r_seen)      return "\r";    else      // This also is returned for single-line document.      return "\n";  }  /**   * Truncate.   * @param n The length to truncate till.   */  public void setLength(int n)  {    length = n;  }  /**   * Get location information for the given region.   * @param from Region start, inclusive.   * @param to Region end, exclusive.   * @return The location, covering the region.   */  public Location getLocation(int from, int to)  {    Location l = new Location();    l.beginLine = line [ from ];    l.endLine = line [ to - 1 ];    l.startPosition = position [ from ];    l.endPosition = position [ to - 1 ] + 1;    return l;  }  /**   * Add the character.   * @param c The character.   * @param pos The character position in the stream (the line number   * is handled internally in the buffer).   */  public void append(char c, int pos)  {    if (length >= chr.length)      expand();    chr [ length ] = c;    position [ length ] = pos;    if (c == '\n')      {        if (!r_seen)          current_line++;        n_seen = true;      }    else if (c == '\r')      {        current_line++;        r_seen = true;      }    line [ length ] = current_line;    length++;  }  /**   * Return char at the given positon.   */  public char charAt(int i)  {    return chr [ i ];  }  /**   * Delete the range   * @param from Start position, inclusive.   * @param to End position, exclusive.   */  public void delete(int from, int to)  {    int len = to - from;    if (len < 1)      throw new AssertionError("Deleting " + from + " till " + to);    int tail = length - to;    System.arraycopy(chr, to, chr, from, tail);    System.arraycopy(position, to, position, from, tail);    System.arraycopy(line, to, line, from, tail);    length = length - len;  }  /**   * Double the buffer size.   */  public void expand()  {    int nSize = 2 * chr.length;    char[] nchr = new char[ nSize ];    int[] nposition = new int[ nSize ];    int[] nline = new int[ nSize ];    System.arraycopy(chr, 0, nchr, 0, chr.length);    System.arraycopy(position, 0, nposition, 0, position.length);    System.arraycopy(line, 0, nline, 0, line.length);    chr = nchr;    position = nposition;    line = nline;  }  /**   * Return length of the occupied part of the buffer.   */  public int length()  {    return length;  }  /**   * Prepare for parsing the new document.   */  public void reset()  {    setLength(0);    r_seen = n_seen = false;  }  public String toString()  {    return new String(chr, 0, length);  }}

⌨️ 快捷键说明

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