示例#1
0
        /// <summary>
        /// Return the contents of this block as a block of characters.
        /// </summary>
        /// <returns>Block of characters.</returns>
        public virtual BlockOfCharacters GetCharacters()
        {
            long nLength = 0;

            for (long nLine = 0; nLine < Elements.Length; nLine++)
            {
                ElementLine oLine = new ElementLine(Elements[nLine].Contents.ToString());
                nLength += oLine.Contents.ToString().Length + 1;
            }
            long nIndex = 0;

            ElementChar[] aElements = new ElementChar[nLength];
            for (long nLine = 0; nLine < Elements.Length; nLine++)
            {
                ElementLine oLine     = new ElementLine(Elements[nLine].Contents.ToString());
                ElementChar oElement  = null;
                char[]      aContents = oLine.Contents.ToString().ToCharArray();
                for (int nPos = 0; nPos < aContents.Length; nPos++)
                {
                    oElement          = new ElementChar(aContents[nPos]);
                    aElements[nIndex] = oElement;
                    nIndex++;
                }
                oElement          = new ElementChar('\n');
                aElements[nIndex] = oElement;
            }
            BlockOfCharacters oBlock = new BlockOfCharacters(aElements);

            return(oBlock);
        }
示例#2
0
        /// <summary>
        /// Read the specified file and return its contents as a block of element lines.
        /// </summary>
        /// <param name="psFile">Text file specification.</param>
        /// <returns>Entire file contents as a block of element lines.</returns>
        public override Block Read(string psFile)
        {
            StreamReader     oSr;
            string           sLine  = string.Empty;
            StringCollection cLines = new StringCollection();

            ElementLine[] aElementLines = null;
            try
            {
                if (File.Exists(psFile))
                {
                    oSr = new StreamReader(psFile);
                    while (!oSr.EndOfStream)
                    {
                        sLine = oSr.ReadLine();
                        cLines.Add(sLine);
                    }
                    oSr.Close();
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            aElementLines = new ElementLine[cLines.Count];
            for (int nCount = 0; nCount < cLines.Count; nCount++)
            {
                aElementLines[nCount] = new ElementLine(cLines[nCount].ToString());
            }
            BlockOfLines oBlock = new BlockOfLines(aElementLines);

            return(oBlock);
        }
示例#3
0
        /// <summary>
        /// Read the specified string list and return its contents as a block of element lines.
        /// </summary>
        /// <param name="pcList">List of strings.</param>
        /// <returns>String list as a block of element lines.</returns>
        public Block ReadLines(List <string> pcLines)
        {
            ElementLine[] aElementLines = new ElementLine[pcLines.Count];
            for (int nCount = 0; nCount < pcLines.Count; nCount++)
            {
                aElementLines[nCount] = new ElementLine(pcLines[nCount].ToString());
            }
            BlockOfLines oBlock = new BlockOfLines(aElementLines);

            return(oBlock);
        }
示例#4
0
        /// <summary>
        /// Check if both elements are equal.
        /// </summary>
        /// <param name="poElement1">Left hand side operand element to compare.</param>
        /// <param name="poElement2">Right hand side operand element to compare.</param>
        /// <returns>True if equal, false otherwise.</returns>
        private static bool AreEqual(ElementLine poElement1, ElementLine poElement2)
        {
            bool bEqual = false;

            if (poElement1.Contents.ToString() == poElement2.Contents.ToString())
            {
                bEqual = true;
            }
            else
            {
                bEqual = false;
            }
            return(bEqual);
        }