RemoveComments() public static method

public static RemoveComments ( string classContents ) : string
classContents string
return string
示例#1
0
        public void SetFromContents(string contents, bool removeComments, bool trimClassContents)
        {
            if (removeComments)
            {
                contents = ParsedClass.RemoveComments(contents);
            }

            int startOfNamespace = contents.IndexOf("namespace ");

            if (startOfNamespace != -1)
            {
                int i = GetClosingBracketOfNamespace(contents);

                try
                {
                    string parsedNamespaceString = contents.Substring(startOfNamespace, i - startOfNamespace + 1);

                    ParsedNamespace parsedNamespace = new ParsedNamespace(parsedNamespaceString, removeComments, trimClassContents);

                    mNamespaces.Add(parsedNamespace);
                }
                catch
                {
                    int m = 3;
                }
            }
        }
示例#2
0
        public ParsedNamespace(string namespaceContents, bool removeComments, bool trimParsedClassContents)
        {
            int indexIntoFile = 0;

            if (removeComments)
            {
                namespaceContents = ParsedClass.RemoveComments(namespaceContents);
            }

            namespaceContents = ParsedClass.RemovePreprocessoredOutCode(namespaceContents);


            #region Get the namespace name

            Name = FlatRedBall.Utilities.StringFunctions.GetWordAfter("namespace ", namespaceContents);


            #endregion


            while (true)
            {
                int startOfEnum = namespaceContents.IndexOf("enum ", indexIntoFile + 1);

                int startOfClass  = namespaceContents.IndexOf("class ", indexIntoFile + 1);
                int startOfStruct = namespaceContents.IndexOf("struct ", indexIntoFile + 1);
                if (startOfStruct != -1 && startOfStruct < startOfClass || startOfClass == -1)
                {
                    startOfClass = startOfStruct;
                }


                int startOfInterface = namespaceContents.IndexOf("interface ", indexIntoFile + 1);

                if (startOfEnum == -1 && startOfClass == -1 && startOfInterface == -1)
                {
                    break;
                }

                if (startOfInterface != -1 && (startOfClass == -1 || startOfInterface < startOfClass))
                {
                    startOfClass = startOfInterface;
                }

                #region Get all enums


                if (startOfEnum != -1 &&
                    (startOfClass == -1 || startOfEnum < startOfClass))
                {
                    ParsedEnum parsedEnum = new ParsedEnum();

                    int startOfLine = 1 + namespaceContents.LastIndexOf('\n', startOfEnum - 1, startOfEnum);


                    parsedEnum.Parse(namespaceContents, ref startOfLine);

                    startOfEnum = namespaceContents.IndexOf("enum ", startOfLine);

                    parsedEnum.Namespace = this.Name;
                    mEnums.Add(parsedEnum);
                    indexIntoFile = startOfLine;
                }

                #endregion

                #region Get all classes



                else if (startOfClass != -1)
                {
                    int i = GetEndOfClassIndex(namespaceContents, startOfClass);

                    indexIntoFile = i;

                    string substring = namespaceContents.Substring(startOfClass, i - startOfClass + 1);

                    ParsedClass parsedClass = new ParsedClass(substring, trimParsedClassContents);

                    parsedClass.Namespace = this.Name;
                    mClasses.Add(parsedClass);
                }
                #endregion
            }
        }