Beispiel #1
0
        private string getNextToken()
        {
            int start = posizione;

            posizione = SkipComments.nextNonComment(stringa, posizione);
            if (posizione < 0)
            {
                posizione = stringa.Length;
                return(stringa.Substring(start));
            }
            char C = stringa[posizione];

            posizione++;

            if (Char.IsLetter(C) || (C == '_'))
            {
                string res = GetKeywordOrIdentifier(stringa, posizione - 1);
                posizione += res.Length - 1;
                return(res);
            }

            if (Char.IsDigit(C))
            {
                string res = GetNumber(stringa, posizione - 1);
                posizione += res.Length - 1;
                return(res);
            }
            if ((C == '\'') || (C == '"'))
            {
                string res = GetStringConstant(stringa, posizione - 1);
                posizione += res.Length - 1;
                return(res);
            }
            return(C.ToString());
        }
Beispiel #2
0
        public static string getFunctionCode(string methodname, string S, out string before, out string after, int ENTER_COUNT)
        {
            int N     = 0;
            int start = 0;

            while ((N < ENTER_COUNT) && (start < S.Length))
            {
                start = S.IndexOf("{", start) + 1;
                N++;
            }

            before = "";
            after  = "";
            int limit = S.IndexOf("{", start);

            while ((limit >= 0) && (IsInsideComment(S, start, limit)))
            {
                limit = S.IndexOf("{", limit + 1);
            }
            if (limit < 0)
            {
                limit = S.Length;
            }
            string pattern = " " + methodname;
            string SS      = S.Substring(start);
            int    next    = S.IndexOf(pattern, start, limit - start);

            while ((next >= 0) && (IsInsideComment(S, start, next)) && (next < limit))
            {
                next = S.IndexOf(pattern, next + 1, limit - next - 1);
            }
            SS = S.Substring(start, limit - start);
            while ((next < 0) && (limit < S.Length))
            {
                SS    = S.Substring(limit);
                start = SkipComments.closeBlock(S, limit + 1, '{', '}');
                if (start < 0)
                {
                    string sss = methodname;
                }
                limit = S.IndexOf("{", start);
                while ((limit >= 0) && (IsInsideComment(S, start, limit)))
                {
                    limit = S.IndexOf("{", limit + 1);
                }
                if (limit < 0)
                {
                    limit = S.Length;
                }
                next = S.IndexOf(pattern, start, limit - start);
                while ((next >= 0) && (IsInsideComment(S, start, next)) && (next < limit))
                {
                    next = S.IndexOf(pattern, next + 1, limit - next - 1);
                }
            }
            if (next < 0)
            {
                before = S;
                after  = "";
                return("");
            }
            int NNNNNNN    = S.Length;
            int startblock = S.LastIndexOf('\n', next, next);
            int idx        = S.IndexOf('{', startblock);
            int stop       = SkipComments.closeBlock(S, idx + 1, '{', '}');

            if (stop < 0)
            {
                stop = S.Length;
            }
            before = S.Substring(0, startblock);
            after  = S.Substring(stop);
            return(S.Substring(startblock, stop - startblock));
        }