Seek() публичный Метод

public Seek ( long offset, System origin ) : long
offset long
origin System
Результат long
Пример #1
0
        public static int FunctionLength(MyStream sr, string s)
        {
            int   count   = 0;
            uint  curPos  = sr.Pos;
            Stack myStack = new Stack();

            s = sr.ReadLine();
            myStack.Push(s);
            bool found = false;

            while ((s != null && myStack.Count > 0))
            {
                count++;
                s = sr.ReadLine();
                if (s.IndexOf("{") != -1)
                {
                    myStack.Push(s);
                }
                if (s.IndexOf("}") != -1)
                {
                    myStack.Pop();
                }
            }
            if (myStack.Count == 0)
            {
                found = true;
            }
            count = count - 1;
            myStack.Clear();
            sr.Seek(curPos);
            return(count);
        }
        /// Function - FunctionLength
        /// <summary>
        /// gets the function line and buffer returns the function length.
        /// </summary>
        /// <param name="sr"> Buffer type MyStream.</param>
        /// <param name="codeLine"> Code line type string</param>
        /// <returns> returns the function length type int.</returns>
        public static int FunctionLength(MyStream sr, string codeLine)
        {
            int   count   = 0;
            uint  curPos  = sr.Pos;
            Stack myStack = new Stack();

            codeLine = sr.ReadLine();
            myStack.Push(codeLine);
            bool found = false;

            while ((codeLine != null && myStack.Count > 0))
            {
                count++;
                codeLine = sr.ReadLine();
                if (codeLine.IndexOf("{") != NOT_FOUND_STRING)
                {
                    myStack.Push(codeLine);
                }
                if (codeLine.IndexOf("}") != NOT_FOUND_STRING)
                {
                    myStack.Pop();
                }
            }
            if (myStack.Count == 0)
            {
                found = true;
            }
            count = count - 1;
            myStack.Clear();
            //returns the buffer to the start of the function.
            sr.Seek(curPos);
            return(count);
        }
Пример #3
0
        /// Function - skipDocumentation
        /// <summary>
        /// skips the documentation in c file in a buffer.
        /// </summary>
        /// <param name="sr"> buffer type MyStream</param>
        /// <param name="codeLine"> string </param>
        /// <returns> returns the amount of rows the documentation was.</returns>
        public static int skipDocumentation(MyStream sr, string codeLine)
        {
            int  count = 0;
            uint pos   = sr.Pos;

            if (codeLine.IndexOf("//") != GeneralConsts.NOT_FOUND_STRING)
            {
                while ((codeLine.IndexOf("//") != GeneralConsts.NOT_FOUND_STRING))
                {
                    pos = sr.Pos;
                    count++;
                    codeLine = sr.ReadLine();
                }
                sr.Seek(pos);
                count--;
            }
            if (codeLine.IndexOf("/*") != GeneralConsts.NOT_FOUND_STRING)
            {
                while (!(codeLine.IndexOf("*/") != GeneralConsts.NOT_FOUND_STRING))
                {
                    count++;
                    codeLine = sr.ReadLine();
                }
            }
            return(count);
        }
        /// Function - SearchPattern
        /// <summary>
        ///
        /// </summary>
        /// <param name="Pattern"> The pattern that it search type Regex.</param>
        /// <param name="returnSize"> size of the return code.</param>
        /// <param name="filePath"> the path of the file type string.</param>
        /// <returns> An array of strings that contains all of the code that matches the patterns.</returns>
        public static string [] SearchPattern(Regex Pattern, string returnSize, string filePath)
        {
            ArrayList results        = new ArrayList();
            MyStream  sr             = new MyStream(filePath, System.Text.Encoding.UTF8);
            uint      pos            = sr.Pos;
            Stack     s              = new Stack();
            string    blockLine      = "";
            bool      modelStopWhile = false;
            string    codeLine;

            while ((codeLine = sr.ReadLine()) != null && !modelStopWhile)
            {
                if (codeLine.IndexOf("{") != GeneralConsts.NOT_FOUND_STRING)
                {
                    pos       = sr.Pos;
                    blockLine = codeLine;
                    s.Push(codeLine);
                }
                if (codeLine.IndexOf("}") != GeneralConsts.NOT_FOUND_STRING)
                {
                    s.Pop();
                }
                if (Pattern.IsMatch(codeLine))
                {
                    if (returnSize == "model")
                    {
                        modelStopWhile = true;
                        sr.Seek(0);
                        results.Add(sr.ReadToEnd());
                    }
                    else if (returnSize == "scope")
                    {
                        if (s.Count == 0)
                        {
                            pos = 0;
                        }
                        if (!results.Contains(ReadAllScope(sr, pos, blockLine)))
                        {
                            results.Add(ReadAllScope(sr, pos, blockLine));
                        }
                    }
                    else if (returnSize == "line")
                    {
                        results.Add(codeLine);
                    }
                }
            }
            string[] finalResult = (string[])results.ToArray(typeof(string));
            return(finalResult);
        }
        /// Function - FindDocumentation
        /// <summary>
        /// Finds the documentation of a function.
        /// </summary>
        /// <param name="sr"> Buffer type MyStream.</param>
        /// <param name="documentation"> Position of the first documentation line type uint.</param>
        /// <param name="firstLineDocumentation"> First documentation line type string.</param>
        /// <param name="functionPos"> Position of the function type uint.</param>
        /// <returns> returns the documentation of the function included.</returns>
        public static string FindDocumentation(MyStream sr, uint documentation, string firstLineDocumentation, uint functionPos)
        {
            string documetationString = firstLineDocumentation + GeneralConsts.NEW_LINE;

            sr.Seek(documentation);
            string codeLine = sr.ReadLine();

            documetationString += codeLine + GeneralConsts.NEW_LINE;
            if (!(firstLineDocumentation.IndexOf("//") != NOT_FOUND_STRING) && !(firstLineDocumentation.IndexOf("/*") != NOT_FOUND_STRING))
            {
                documetationString = GeneralConsts.EMPTY_STRING;
            }
            if ((firstLineDocumentation.IndexOf("/*") != NOT_FOUND_STRING))
            {
                while (!(codeLine.IndexOf("*/") != NOT_FOUND_STRING))
                {
                    codeLine            = sr.ReadLine();
                    documetationString += codeLine + GeneralConsts.NEW_LINE;
                }
            }
            sr.Seek(functionPos);
            return(documetationString);
        }
Пример #6
0
        public static string findDocumentation(MyStream sr, uint documentation, string firstLineDocumentation, uint functionPos)
        {
            string documetationString = firstLineDocumentation + "\n\r";

            sr.Seek(documentation);
            string s = sr.ReadLine();

            documetationString += s + "\n\r";
            if (!(firstLineDocumentation.IndexOf("//") != -1) && !(firstLineDocumentation.IndexOf("/*") != -1))
            {
                documetationString = "No documentation for this function";
            }
            if ((firstLineDocumentation.IndexOf("/*") != -1))
            {
                while (!(s.IndexOf("*/") != -1))
                {
                    s = sr.ReadLine();
                    documetationString += s + "\n\r";
                }
            }
            sr.Seek(functionPos);
            return(documetationString);
        }
        /// Function - ReadAllScope
        /// <summary>
        /// reads all of the scope that the code line is in.
        /// </summary>
        /// <param name="sr"> buffer type MyStream.</param>
        /// <param name="pos"> position of the line type uint.</param>
        /// <param name="line"> code line type string.</param>
        /// <returns> the string of all the scope.</returns>
        public static string ReadAllScope(MyStream sr, uint pos, string line)
        {
            string result = "";

            if (pos == 0)
            {
                result = line;
            }
            else
            {
                sr.Seek(pos);
                result = line + GeneralConsts.NEW_LINE + FunctionCode(sr, ref line);
            }
            return(result);
        }
Пример #8
0
        /// Function - NextScopeLength
        /// <summary>
        ///  in order to find function length or struct length or "next scope" this function can be used.
        /// </summary>
        /// <param name="sr"> type MyStream buffer for the file. </param>
        /// <param name="codeLine"> refference of the current code line type string. </param>
        /// <param name="count"> refference of the length of the scope type int. </param>
        /// <param name="Seek"> bool type parameter for returning the buffer to where it started from
        ///                     or to keep the buffer where it is after the scope ends. </param>
        /// <returns></returns>
        public static bool NextScopeLength(MyStream sr, ref string codeLine, ref int count, bool Seek)
        {
            //stack to count the blocks.
            Stack myStack = new Stack();
            //saving the current position of the buffer.
            uint   curPos    = sr.Pos;
            string ScopeName = new string(codeLine.ToCharArray());

            codeLine = sr.ReadLine();
            myStack.Push(codeLine);
            bool found = false;

            while ((codeLine != null && myStack.Count > 0))
            {
                count++;
                codeLine = sr.ReadLine();
                if (codeLine.IndexOf("{") != GeneralConsts.NOT_FOUND_STRING)
                {
                    myStack.Push(codeLine);
                }
                if (codeLine.IndexOf("}") != GeneralConsts.NOT_FOUND_STRING)
                {
                    myStack.Pop();
                }
            }
            if (myStack.Count == 0)
            {
                found = true;
            }
            count = count - 1;
            //checking the bool for seeking.
            if (Seek)
            {
                sr.Seek(curPos);
                codeLine = ScopeName;
            }
            myStack.Clear();
            return(found);
        }
Пример #9
0
 public override long Seek(long offset, SeekOrigin origin)
 {
     AssertInvariants();
     Contracts.Check(!_disposed, "Stream already disposed");
     return(MyStream.Seek(offset, origin));
 }