Exemple #1
0
 private static Zen <FiniteString> At(Zen <IList <ushort> > s, Zen <ushort> i, int current)
 {
     return(s.Case(
                empty: FiniteString.Empty(),
                cons: (hd, tl) =>
                If(i == (ushort)current, FiniteString.Singleton(hd), At(tl, i, current + 1))));
 }
Exemple #2
0
 /// <summary>
 /// Transform a string by modifying its characters.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="f">The transformation function.</param>
 /// <returns>A new string.</returns>
 public static Zen <FiniteString> Transform(this Zen <FiniteString> s, Func <Zen <IList <ushort> >, Zen <IList <ushort> > > f)
 {
     return(FiniteString.Create(f(s.GetCharacters())));
 }
Exemple #3
0
 /// <summary>
 /// Replaces all occurrences of a given character with another.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="src">The source value.</param>
 /// <param name="dst">The destination value.</param>
 /// <returns>A new string.</returns>
 public static Zen <FiniteString> ReplaceAll(this Zen <FiniteString> s, Zen <ushort> src, Zen <ushort> dst)
 {
     return(FiniteString.Create(s.GetCharacters().Select(c => If(c == src, dst, c))));
 }
Exemple #4
0
 /// <summary>
 /// Gets the substring at an offset and for a given length..
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="len">The length.</param>
 /// <returns>An index.</returns>
 public static Zen <FiniteString> SubString(this Zen <FiniteString> s, Zen <ushort> offset, Zen <ushort> len)
 {
     return(FiniteString.Create(s.GetCharacters().Drop(offset).Take(len)));
 }
Exemple #5
0
 /// <summary>
 /// Concatenation of two strings.
 /// </summary>
 /// <param name="s1">The first string.</param>
 /// <param name="s2">The second string.</param>
 /// <returns>The concatenated string.</returns>
 public static Zen <FiniteString> Concat(this Zen <FiniteString> s1, Zen <FiniteString> s2)
 {
     return(FiniteString.Create(s1.GetCharacters().Append(s2.GetCharacters())));
 }