Package gnu.lists

Class FString

All Implemented Interfaces:
BoundedHashable, Array<Char>, AVector<Char>, CharSeq, Consumable, Sequence<Char>, Externalizable, Serializable, Appendable, CharSequence, Comparable, Iterable<Char>, Collection<Char>, List<Char>, RandomAccess, SequencedCollection<Char>
Direct Known Subclasses:
CharBuffer

public class FString extends AbstractCharVector<Char> implements Appendable, CharSeq, Consumable
Simple adjustable-length vector whose elements are 32-bit code points Used for the Scheme string type. This isn't a regular SimpleVector because character indexing isn't a simple lookup. "Sub-range mode" is not used (at least not for Kawa Scheme): if you need an immutable sub-string, use an IString (or java.lang.String).
See Also:
  • Constructor Details

    • FString

      public FString()
    • FString

      public FString(int num)
    • FString

      public FString(int num, int value)
    • FString

      public FString(char[] values)
      Create an FString from a char[]. Note that this contructor does *not* copy the argument.
    • FString

      public FString(char[] buffer, int offset, int length)
      This constructor makes a copy.
    • FString

      public FString(CharSequence seq)
    • FString

      public FString(CharSequence seq, int offset, int length)
      Copy a substring of a CharSequence.
      Parameters:
      offset - - start offset in 16-bit char units
      length - - length in 16-bit char units
  • Method Details

    • size

      public int size()
      Description copied from interface: Sequence
      See java.util.List.
      Specified by:
      size in interface Collection<Char>
      Specified by:
      size in interface List<Char>
      Specified by:
      size in interface Sequence<Char>
      Overrides:
      size in class SimpleVector<Char>
    • effectiveIndex

      public int effectiveIndex(int index)
      Specified by:
      effectiveIndex in interface Array<Char>
      Overrides:
      effectiveIndex in class SimpleVector<Char>
      Parameters:
      index - measured in Unicode code points (characters)
    • createPos

      public int createPos(int index, boolean isAfter)
      Description copied from class: AbstractSequence
      Generate a position at a given index. The result is a position cookie that must be free'd with releasePos.
      Overrides:
      createPos in class AbstractSequence<Char>
      Parameters:
      index - offset from beginning of desired position
      isAfter - should the position have the isAfter property
    • nextIndex

      protected int nextIndex(int ipos)
      Description copied from class: AbstractSequence
      Get the offset from the beginning corresponding to a position cookie.
      Overrides:
      nextIndex in class AbstractSequence<Char>
    • createRelativePos

      public int createRelativePos(int pos, int delta, boolean isAfter)
      Overrides:
      createRelativePos in class AbstractSequence<Char>
    • alloc

      public static FString alloc(int sz)
      Create a empty string, but with a given initial buffer size.
    • getRaw

      public final Char getRaw(int index)
      Description copied from interface: Array
      Given an "effective index", return element as object.
      Specified by:
      getRaw in interface Array<Char>
      Overrides:
      getRaw in class AbstractSequence<Char>
    • get

      public final Char get(int index)
      Description copied from interface: Sequence
      See java.util.List.
      Specified by:
      get in interface Array<Char>
      Specified by:
      get in interface List<Char>
      Specified by:
      get in interface Sequence<Char>
      Overrides:
      get in class AbstractSequence<Char>
      Parameters:
      index - offset in character units (Unicode code points)
    • indexOf

      public int indexOf(int ch, int fromChar)
      Parameters:
      fromChar - offset in 16-bit code units
    • lastIndexOf

      public int lastIndexOf(int ch, int fromChar)
      Parameters:
      fromChar - offset in 16-bit code units
    • set

      public Char set(int index, Char value)
      Description copied from interface: Sequence
      See java.util.List.
      Specified by:
      set in interface List<Char>
      Specified by:
      set in interface Sequence<Char>
      Overrides:
      set in class AbstractSequence<Char>
      Parameters:
      index - offset in character units (Unicode code points)
    • setRaw

      public final void setRaw(int index, Char value)
      Description copied from class: AbstractSequence
      Given an "effective index", set selected element.
      Specified by:
      setRaw in interface Array<Char>
      Overrides:
      setRaw in class AbstractSequence<Char>
      Parameters:
      index - offset in character units (Unicode code points)
    • characterAt

      public final int characterAt(int index)
      Parameters:
      index - offset in 16-bit code units
    • toCharArray

      public char[] toCharArray()
      Return a char[] contain the characters of this string. It is unspecified if the result is a copy or shares with this FString.
    • shift

      public void shift(int srcStart, int dstStart, int count)
      Overrides:
      shift in class SimpleVector<Char>
    • copy

      public FString copy(int start, int end)
    • addAll

      public boolean addAll(CharSequence s)
    • insert

      public void insert(int where, int ch, boolean beforeMarkers)
    • insert

      public void insert(int where, String str, boolean beforeMarkers)
    • addAllStrings

      public void addAllStrings(Object[] args, int startIndex)
      Append arguments to this FString. Used to implement Scheme's string-append.
      Parameters:
      args - an array of FString value
      startIndex - index of first string in args to use
    • toString

      public String toString()
      Specified by:
      toString in interface CharSeq
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class AbstractSequence<Char>
    • substring

      public String substring(int start, int end)
    • subSequence

      public CharSeq subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • setCharAt

      public void setCharAt(int index, char ch)
      Specified by:
      setCharAt in interface CharSeq
    • setCharacterAt

      public void setCharacterAt(int index, int ch)
      Specified by:
      setCharacterAt in interface CharSeq
    • replace

      public void replace(CharSequence src, int srcStart, int srcEnd, int dstStart, int dstEnd)
      Replace a substring of this string with another. The two strings may have different lengths, so this generalizes insertion and deletion. All indexes are code-unit (16-bit char) offsets.
    • setCharAtBuffer

      public void setCharAtBuffer(int index, char ch)
    • insertRepeated

      public void insertRepeated(int where, int value, int count)
    • replace

      public void replace(int where, char[] chars, int start, int count)
    • replace

      public void replace(int where, String string)
    • equals

      public boolean equals(Object obj)
      Description copied from class: AbstractCharVector
      Must override, since we override hashCode.
      Specified by:
      equals in interface Collection<Char>
      Specified by:
      equals in interface List<Char>
      Specified by:
      equals in class AbstractCharVector<Char>
    • newInstance

      protected FString newInstance(int newLength)
      Specified by:
      newInstance in class SimpleVector<Char>
    • getElementKind

      public int getElementKind()
      Specified by:
      getElementKind in interface Array<Char>
      Overrides:
      getElementKind in class AbstractSequence<Char>
    • getTag

      public String getTag()
      Description copied from class: SimpleVector
      This is convenience hack for printing "uniform vectors" (srfi 4). It may go away without notice!
      Overrides:
      getTag in class SimpleVector<Char>
    • consumePosRange

      public void consumePosRange(int iposStart, int iposEnd, Consumer out)
      Overrides:
      consumePosRange in class AbstractSequence<Char>
    • append

      public FString append(char c)
      Specified by:
      append in interface Appendable
    • appendCharacter

      public FString appendCharacter(int c)
      Append a Unicode code point.
    • append

      public FString append(CharSequence csq)
      Specified by:
      append in interface Appendable
    • append

      public FString append(CharSequence csq, int start, int end)
      Specified by:
      append in interface Appendable
    • append

      public FString append(Object obj)
    • prependCharacter

      public FString prependCharacter(int c)
    • prepend

      public FString prepend(CharSequence str, int start, int end)
    • prepend

      public FString prepend(Object obj)
    • writeTo

      public void writeTo(int start, int count, Appendable dest) throws IOException
      Description copied from interface: CharSeq
      Append a specified subsequence to an Appendable. An allowable implementation is: dest.append(this, start, start+count). Hence implementors of Appendable should avoid calling writeTo - though they can call getChars.
      Specified by:
      writeTo in interface CharSeq
      Throws:
      IOException
    • writeTo

      public void writeTo(Appendable dest) throws IOException
      Specified by:
      writeTo in interface CharSeq
      Throws:
      IOException