public final class LazyString
extends java.lang.Object
implements java.lang.CharSequence
Modifier and Type | Field and Description |
---|---|
static LazyString |
empty
The empty string.
|
static F<Stream<java.lang.Character>,LazyString> |
fromStream
First-class conversion from character streams to lazy strings.
|
static F<LazyString,Stream<java.lang.Character>> |
toStream
First-class conversion from lazy strings to streams.
|
static F<LazyString,java.lang.String> |
toString
First-class conversion from lazy strings to String.
|
Modifier and Type | Method and Description |
---|---|
LazyString |
append(LazyString cs)
Appends the given lazy string to the end of this lazy string.
|
LazyString |
append(java.lang.String s)
Appends the given String to the end of this lazy string.
|
LazyString |
bind(F<java.lang.Character,LazyString> f) |
char |
charAt(int index)
Returns the caracter at the specified index.
|
boolean |
contains(LazyString cs)
Returns true if the given lazy string is a substring of this lazy string.
|
boolean |
endsWith(LazyString cs)
Returns true if the given lazy string is a suffix of this lazy string.
|
java.lang.String |
eval() |
static LazyString |
fromStream(Stream<java.lang.Character> s)
Constructs a lazy string from a stream of characters.
|
char |
head()
Returns the first character of this string.
|
Option<java.lang.Integer> |
indexOf(char c)
Returns the first index of the given character in this lazy string, if present.
|
Option<java.lang.Integer> |
indexOf(LazyString cs)
Returns the first index of the given substring in this lazy string, if present.
|
boolean |
isEmpty()
Checks if this string is empty.
|
int |
length()
The length of the lazy string.
|
static F<LazyString,Stream<LazyString>> |
lines_() |
Stream<LazyString> |
lines()
Splits this lazy string into lines.
|
LazyString |
map(F<java.lang.Character,java.lang.Character> f) |
boolean |
matches(java.lang.String regex)
Regular expression pattern matching.
|
LazyString |
reverse()
Returns the reverse of this string.
|
Stream<LazyString> |
split(char c)
Splits this lazy string by the given delimiter character.
|
Stream<LazyString> |
split(F<java.lang.Character,java.lang.Boolean> p)
Splits this lazy string by characters matching the given predicate.
|
static F<LazyString,F<LazyString,java.lang.Boolean>> |
startsWith()
First-class prefix check.
|
boolean |
startsWith(LazyString cs)
Returns true if the given lazy string is a prefix of this lazy string.
|
static LazyString |
str(java.lang.String s)
Constructs a lazy string from a String.
|
java.lang.CharSequence |
subSequence(int start,
int end)
Gets the specified subsequence of this lazy string.
|
LazyString |
tail()
Returns all but the first character of this string.
|
Stream<java.lang.Character> |
toStream()
Gives a stream representation of this lazy string.
|
java.lang.String |
toString() |
java.lang.String |
toStringEager()
Returns the String representation of this lazy string.
|
java.lang.String |
toStringLazy() |
static F<Stream<LazyString>,LazyString> |
unlines_() |
static LazyString |
unlines(Stream<LazyString> str)
Joins the given stream of lazy strings into one, separated by newlines.
|
static LazyString |
unwords(Stream<LazyString> str)
Joins the given stream of lazy strings into one, separated by spaces.
|
Stream<LazyString> |
words()
Splits this lazy string into words by spaces.
|
public static final LazyString empty
public static final F<LazyString,Stream<java.lang.Character>> toStream
public static final F<LazyString,java.lang.String> toString
public static final F<Stream<java.lang.Character>,LazyString> fromStream
public static LazyString str(java.lang.String s)
s
- A string from which to construct a lazy string.public static LazyString fromStream(Stream<java.lang.Character> s)
s
- A stream of characters.public Stream<java.lang.Character> toStream()
public int length()
length
in interface java.lang.CharSequence
public char charAt(int index)
charAt
in interface java.lang.CharSequence
index
- The index for the character to be returned.public java.lang.CharSequence subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
start
- The character index of this lazy string at which to start the subsequence.end
- The character index of this lazy string at which to end the subsequence.public java.lang.String toStringEager()
public java.lang.String toStringLazy()
public java.lang.String toString()
toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public java.lang.String eval()
public LazyString append(LazyString cs)
cs
- A lazy string to append to this one.public LazyString append(java.lang.String s)
s
- A String to append to this lazy string.public boolean contains(LazyString cs)
cs
- A substring to find in this lazy string.public boolean endsWith(LazyString cs)
cs
- A string to find at the end of this lazy string.public boolean startsWith(LazyString cs)
cs
- A string to find at the start of this lazy string.public static F<LazyString,F<LazyString,java.lang.Boolean>> startsWith()
public char head()
public LazyString tail()
public boolean isEmpty()
public LazyString reverse()
public Option<java.lang.Integer> indexOf(char c)
c
- A character to find in this lazy string.public Option<java.lang.Integer> indexOf(LazyString cs)
cs
- A substring to find in this lazy string.public boolean matches(java.lang.String regex)
regex
- A regular expression to match this lazy string.public Stream<LazyString> split(F<java.lang.Character,java.lang.Boolean> p)
p
- A predicate that matches characters to be considered delimiters.public LazyString map(F<java.lang.Character,java.lang.Character> f)
public LazyString bind(F<java.lang.Character,LazyString> f)
public Stream<LazyString> split(char c)
c
- A delimiter character at which to split.public Stream<LazyString> words()
public Stream<LazyString> lines()
public static F<LazyString,Stream<LazyString>> lines_()
public static LazyString unlines(Stream<LazyString> str)
str
- A stream of lazy strings to join by newlines.public static F<Stream<LazyString>,LazyString> unlines_()
public static LazyString unwords(Stream<LazyString> str)
str
- A stream of lazy strings to join by spaces.