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

            return(CreateLineIterator(self, options));
        }
示例#2
0
 private static void CheckOptions(TextReaderCodaOptions options)
 {
     if (options != TextReaderCodaOptions.None && options != TextReaderCodaOptions.CloseReader)
     {
         throw new ArgumentException("options", "Invalid `options' value.");
     }
 }
示例#3
0
 private static IEnumerable <string> CreateTokensIterator(TextReader self, TextReaderCodaOptions 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 & TextReaderCodaOptions.CloseReader) != 0)
         {
             self.Close();
             self.Dispose();
         }
     }
 }
示例#4
0
        public static IEnumerable <string> Words(this TextReader self, TextReaderCodaOptions options)
        {
            Check.Self(self);
            CheckOptions(options);

            return(Tokens(self, options, (p, c) => !char.IsWhiteSpace(c)));
        }
示例#5
0
        public static IEnumerable<string> Lines(this TextReader self, TextReaderCodaOptions options)
        {
            Check.Self (self);
            CheckOptions (options);

            return CreateLineIterator (self, options);
        }
示例#6
0
        public static IEnumerable<string> Tokens(this TextReader self, TextReaderCodaOptions 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);
        }
示例#7
0
        public static IEnumerable <string> Tokens(this TextReader self, TextReaderCodaOptions 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));
        }
示例#8
0
 private static IEnumerable <string> CreateLineIterator(TextReader self, TextReaderCodaOptions options)
 {
     try {
         string line;
         while ((line = self.ReadLine()) != null)
         {
             yield return(line);
         }
     } finally {
         if ((options & TextReaderCodaOptions.CloseReader) != 0)
         {
             self.Close();
             self.Dispose();
         }
     }
 }
示例#9
0
        public static IEnumerable<string> Words(this TextReader self, TextReaderCodaOptions options)
        {
            Check.Self (self);
            CheckOptions (options);

            return Tokens (self, options, (p, c) => !char.IsWhiteSpace (c));
        }
示例#10
0
 private static IEnumerable<string> CreateTokensIterator(TextReader self, TextReaderCodaOptions 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 & TextReaderCodaOptions.CloseReader) != 0) {
             self.Close ();
             self.Dispose ();
         }
     }
 }
示例#11
0
 private static IEnumerable<string> CreateLineIterator(TextReader self, TextReaderCodaOptions options)
 {
     try {
         string line;
         while ((line = self.ReadLine ()) != null)
             yield return line;
     } finally {
         if ((options & TextReaderCodaOptions.CloseReader) != 0) {
             self.Close ();
             self.Dispose ();
         }
     }
 }
示例#12
0
 private static void CheckOptions(TextReaderCodaOptions options)
 {
     if (options != TextReaderCodaOptions.None && options != TextReaderCodaOptions.CloseReader)
         throw new ArgumentException ("options", "Invalid `options' value.");
 }