示例#1
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="text"></param>
        public TextMemory(string text)
        {
            _lines = new TextLineCollection();
            using (StringReader sr = new StringReader(text))
            {
                String line;
                // Read and display lines from the file until the end of
                // the file is reached.
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Length > MaxLineLength)
                    {
                        throw new InvalidOperationException(
                            string.Format("File contains a line greater than {0} characters.",
                            MaxLineLength.ToString()));
                    }
                    if (TrimWhiteSpace)
                    {
                        line = line.Trim();
                    }
                    _lines.Add(new TextLine(line));
                }

                if (this.RemoveOuterBlankLines)
                {
                    // Remove blank lines at start
                    while (_lines.Count>0)
                    {
                        // Check if the first line is blank
                        if (_lines[0].Line.Length==0)
                        {
                            _lines.RemoveAt(0);
                        }
                        else
                        {
                            break;
                        }
                    }
                    // Remove blank lines at end
                    while (_lines.Count>0)
                    {
                        // Check if the last line is blank
                        if (_lines[_lines.Count-1].Line.Length==0)
                        {
                            _lines.RemoveAt(_lines.Count-1);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="text"></param>
        public TextMemory(string text)
        {
            _lines = new TextLineCollection();
            using (StringReader sr = new StringReader(text))
            {
                String line;
                // Read and display lines from the file until the end of
                // the file is reached.
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Length > MaxLineLength)
                    {
                        throw new InvalidOperationException(
                                  string.Format("File contains a line greater than {0} characters.",
                                                MaxLineLength.ToString()));
                    }
                    if (TrimWhiteSpace)
                    {
                        line = line.Trim();
                    }
                    _lines.Add(new TextLine(line));
                }

                if (this.RemoveOuterBlankLines)
                {
                    // Remove blank lines at start
                    while (_lines.Count > 0)
                    {
                        // Check if the first line is blank
                        if (_lines[0].Line.Length == 0)
                        {
                            _lines.RemoveAt(0);
                        }
                        else
                        {
                            break;
                        }
                    }
                    // Remove blank lines at end
                    while (_lines.Count > 0)
                    {
                        // Check if the last line is blank
                        if (_lines[_lines.Count - 1].Line.Length == 0)
                        {
                            _lines.RemoveAt(_lines.Count - 1);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
示例#3
0
 //UPDATE
 internal TextLineCollectionEnumerator(TextLineCollection collection)
 {
     _index = -1;
     _collection = collection;
 }
示例#4
0
 //UPDATE
 internal TextLineCollectionEnumerator(TextLineCollection collection)
 {
     _index      = -1;
     _collection = collection;
 }