コード例 #1
0
        public void PadRawfile(int index)
        {
            RawFileData r = FindRawfile(index);

            if (r.Size >= r.OriginalSize)
            {
                throw new Exception("Rawfile size >= original size");
            }

            int required = r.OriginalSize - r.Size;

            if (required < 2)
            {
                throw new Exception("Not enough space to place comment");
            }

            string text = r.Contents + "//";

            for (int i = 0; i < required - 2; ++i)
            {
                text += "/";
            }

            r.Contents = text;
        }
コード例 #2
0
        private RawFileData FindRawfile(int index)
        {
            RawFileData result = assetData.RawFiles.Find(r => r.Index == index);

            if (result == null)
            {
                throw new FileNotFoundException("Rawfile with index " + index + " not found");
            }
            return(result);
        }
コード例 #3
0
        public void RawfileRemoveComments(int index)
        {
            RawFileData r = FindRawfile(index);

            string[] lines = r.Contents.Split(new char[] { '\r', '\n' });

            int oneLineCommentIndex        = -1;
            int multiLineCommentIndexStart = -1;
            int multiLineCommentIndexEnd   = -1;
            int devCommentIndexStart       = -1;
            int devCommentIndexEnd         = -1;

            bool isInMultiLineComment = false;
            bool isInDevComment       = false;

            for (int i = 0; i < lines.Length; ++i)
            {
                if (isInMultiLineComment)
                {
                    multiLineCommentIndexEnd = lines[i].IndexOf("*/");
                    if (multiLineCommentIndexEnd != -1)
                    {
                        isInMultiLineComment = false;
                        lines[i]             = lines[i].Substring(multiLineCommentIndexEnd + 2);
                    }
                    else
                    {
                        lines[i] = "";
                        continue;
                    }
                }
                if (isInDevComment)
                {
                    devCommentIndexEnd = lines[i].IndexOf("#/");
                    if (devCommentIndexEnd != -1)
                    {
                        isInDevComment = false;
                        lines[i]       = lines[i].Substring(devCommentIndexEnd + 2);
                    }
                    else
                    {
                        lines[i] = "";
                        continue;
                    }
                }
                //one-line comment
                oneLineCommentIndex = lines[i].IndexOf("//");
                if (oneLineCommentIndex != -1)
                {
                    lines[i] = lines[i].Substring(0, oneLineCommentIndex);
                }

                //multi-line comment
                multiLineCommentIndexStart = lines[i].IndexOf("/*");
                if (multiLineCommentIndexStart != -1)
                {
                    multiLineCommentIndexEnd = lines[i].IndexOf("*/");
                    if (multiLineCommentIndexEnd == -1)
                    {
                        isInMultiLineComment = true;
                        lines[i]             = lines[i].Substring(0, multiLineCommentIndexStart);
                    }
                    else
                    {
                        lines[i] = lines[i].Substring(0, multiLineCommentIndexStart) + lines[i].Substring(multiLineCommentIndexEnd + 2);
                    }

                    continue;
                }

                //dev comment
                devCommentIndexStart = lines[i].IndexOf("/#");
                if (devCommentIndexStart != -1)
                {
                    devCommentIndexEnd = lines[i].IndexOf("#/");
                    if (devCommentIndexEnd == -1)
                    {
                        isInMultiLineComment = true;
                        lines[i]             = lines[i].Substring(0, devCommentIndexStart);
                    }
                    else
                    {
                        lines[i] = lines[i].Substring(0, devCommentIndexStart) + lines[i].Substring(devCommentIndexEnd + 2);
                    }

                    continue;
                }
            }

            string text = "";

            for (int i = 0; i < lines.Length; ++i)
            {
                if (lines[i] != "")
                {
                    text += (i == lines.Length - 1 ? lines[i] : lines[i] + "\r\n");
                }
            }

            r.Contents = text;
        }