Example #1
0
        public static IEnumerable<string> Lines(this TextReader self, TextReaderRocksOptions options)
        {
            Check.Self (self);
            CheckOptions (options);

            return CreateLineIterator (self, options);
        }
Example #2
0
 private static void CheckOptions(TextReaderRocksOptions options)
 {
     if (options != TextReaderRocksOptions.None && options != TextReaderRocksOptions.CloseReader)
     {
         throw new ArgumentException("options", "Invalid `options' value.");
     }
 }
Example #3
0
        public static IEnumerable <string> Lines(this TextReader self, TextReaderRocksOptions options)
        {
            Check.Self(self);
            CheckOptions(options);

            return(CreateLineIterator(self, options));
        }
Example #4
0
        public static IEnumerable <string> Words(this TextReader self, TextReaderRocksOptions options)
        {
            Check.Self(self);
            CheckOptions(options);

            return(Tokens(self, options, (p, c) => !char.IsWhiteSpace(c)));
        }
Example #5
0
 private static IEnumerable <string> CreateTokensIterator(TextReader self, TextReaderRocksOptions options, Func <char?, char, bool>[] categories)
 {
     try {
         var cats = categories.Select(
             c => Lambda.F((StringBuilder buf, char ch) =>
                           c(buf.Length == 0 ? ((char?)null) : (char?)buf [buf.Length - 1], ch)));
         foreach (var t in Chars(self).Tokens(
                      new StringBuilder(),
                      (buf, c) => buf.Append(c),
                      buf => {
             var r = buf.ToString();
             buf.Length = 0;
             return(Tuple.Create(r, buf));
         },
                      cats.ToArray()))
         {
             yield return(t);
         }
     } finally {
         if ((options & TextReaderRocksOptions.CloseReader) != 0)
         {
             self.Close();
             self.Dispose();
         }
     }
 }
Example #6
0
        public static IEnumerable<string> Tokens(this TextReader self, TextReaderRocksOptions options, params Func<char?, char, bool>[] categories)
        {
            Check.Self (self);
            CheckOptions (options);
            Check.Categories (categories);
            if (categories.Length == 0)
                throw new ArgumentException ("categories", "Must provide at least one catagory");

            return CreateTokensIterator (self, options, categories);
        }
Example #7
0
        public static IEnumerable <string> Tokens(this TextReader self, TextReaderRocksOptions options, params Func <char?, char, bool>[] categories)
        {
            Check.Self(self);
            CheckOptions(options);
            Check.Categories(categories);
            if (categories.Length == 0)
            {
                throw new ArgumentException("categories", "Must provide at least one catagory");
            }

            return(CreateTokensIterator(self, options, categories));
        }
Example #8
0
 private static IEnumerable <string> CreateLineIterator(TextReader self, TextReaderRocksOptions options)
 {
     try {
         string line;
         while ((line = self.ReadLine()) != null)
         {
             yield return(line);
         }
     } finally {
         if ((options & TextReaderRocksOptions.CloseReader) != 0)
         {
             self.Close();
             self.Dispose();
         }
     }
 }
Example #9
0
        public static IEnumerable<string> Words(this TextReader self, TextReaderRocksOptions options)
        {
            Check.Self (self);
            CheckOptions (options);

            return Tokens (self, options, (p, c) => !char.IsWhiteSpace (c));
        }
Example #10
0
 private static IEnumerable<string> CreateTokensIterator(TextReader self, TextReaderRocksOptions options, Func<char?, char, bool>[] categories)
 {
     try {
         var cats = categories.Select (
                 c => Lambda.F ((StringBuilder buf, char ch) =>
                     c (buf.Length == 0 ? ((char?) null) : (char?) buf [buf.Length-1], ch)));
         foreach (var t in Chars (self).Tokens (
                     new StringBuilder (),
                     (buf, c) => buf.Append (c),
                     buf => {
                         var r = buf.ToString ();
                         buf.Length = 0;
                         return Tuple.Create (r, buf);
                     },
                     cats.ToArray ()))
             yield return t;
     } finally {
         if ((options & TextReaderRocksOptions.CloseReader) != 0) {
             self.Close ();
             self.Dispose ();
         }
     }
 }
Example #11
0
 private static IEnumerable<string> CreateLineIterator(TextReader self, TextReaderRocksOptions options)
 {
     try {
         string line;
         while ((line = self.ReadLine ()) != null)
             yield return line;
     } finally {
         if ((options & TextReaderRocksOptions.CloseReader) != 0) {
             self.Close ();
             self.Dispose ();
         }
     }
 }
Example #12
0
 private static void CheckOptions(TextReaderRocksOptions options)
 {
     if (options != TextReaderRocksOptions.None && options != TextReaderRocksOptions.CloseReader)
         throw new ArgumentException ("options", "Invalid `options' value.");
 }