示例#1
0
        /// <summary>
        /// Read the specified text file and return its contents as a block of element characters.
        /// </summary>
        /// <param name="psFile">Text file specification.</param>
        /// <returns>Entire file contents as a block of element characters.</returns>
        public override Block Read(string psFile)
        {
            StreamReader oSr;
            string       sContents = string.Empty;

            ElementChar[] aElementChars = null;
            try
            {
                if (File.Exists(psFile))
                {
                    oSr       = new StreamReader(psFile);
                    sContents = oSr.ReadToEnd();
                    oSr.Close();
                }
                else
                {
                    sContents = string.Empty;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }
            aElementChars = new ElementChar[sContents.Length];
            char[] aCharacters = sContents.ToCharArray();
            for (int nCount = 0; nCount < aCharacters.Length; nCount++)
            {
                aElementChars[nCount] = new ElementChar(aCharacters[nCount]);
            }
            BlockOfCharacters oBlock = new BlockOfCharacters(aElementChars);

            return(oBlock);
        }
示例#2
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);
        }
示例#3
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(ElementChar poElement1, ElementChar poElement2)
        {
            bool bEqual = false;

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