Exemplo n.º 1
0
        /// <summary>
        /// Gets the first index of a substring in a
        /// string starting at an offset.
        /// </summary>
        /// <param name="s">The string.</param>
        /// <param name="sub">The substring.</param>
        /// <param name="offset">The offset.</param>
        /// <returns>An index.</returns>
        public static Zen <Option <ushort> > IndexOf(this Zen <FiniteString> s, Zen <FiniteString> sub, Zen <ushort> offset)
        {
            var trimmed = s.GetCharacters().Drop(offset);
            var idx     = IndexOf(trimmed, sub.GetCharacters(), 0);

            return(If(idx.HasValue(), Some(idx.Value() + offset), idx));
        }
Exemplo n.º 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())));
 }
Exemplo n.º 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))));
 }
Exemplo n.º 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)));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Gets the first index of a substring in a string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="sub">The substring.</param>
 /// <returns>An index.</returns>
 public static Zen <Option <ushort> > IndexOf(this Zen <FiniteString> s, Zen <FiniteString> sub)
 {
     return(IndexOf(s.GetCharacters(), sub.GetCharacters(), 0));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Substring of length 1 at the offset.
 /// Empty if the offset is invalid.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="i">The index.</param>
 /// <returns>The substring.</returns>
 public static Zen <FiniteString> At(this Zen <FiniteString> s, Zen <ushort> i)
 {
     return(At(s.GetCharacters(), i, 0));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Whether a string contains a substring.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="sub">The substring.</param>
 /// <returns>A boolean.</returns>
 public static Zen <bool> Contains(this Zen <FiniteString> s, Zen <FiniteString> sub)
 {
     return(Contains(s.GetCharacters(), sub.GetCharacters()));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Whether a string is a suffix of another.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="suf">The suffix.</param>
 /// <returns>A boolean.</returns>
 public static Zen <bool> EndsWith(this Zen <FiniteString> s, Zen <FiniteString> suf)
 {
     return(StartsWith(s.GetCharacters().Reverse(), suf.GetCharacters().Reverse()));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Whether a string is a prefix of another.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <param name="pre">The prefix.</param>
 /// <returns>A boolean.</returns>
 public static Zen <bool> StartsWith(this Zen <FiniteString> s, Zen <FiniteString> pre)
 {
     return(StartsWith(s.GetCharacters(), pre.GetCharacters()));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Gets the length of the string.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>The length.</returns>
 public static Zen <ushort> Length(this Zen <FiniteString> s)
 {
     return(s.GetCharacters().Length());
 }
Exemplo n.º 11
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())));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Get whether a string is empty.
 /// </summary>
 /// <param name="s">The string.</param>
 /// <returns>A boolean.</returns>
 public static Zen <bool> IsEmpty(this Zen <FiniteString> s)
 {
     return(s.GetCharacters().IsEmpty());
 }