Exemple #1
0
        public static SliceSection Parse(IList <string> lines, int lineStart)
        {
            var section = new SliceSection
            {
                Lines = new List <string>()
            };

            for (var pos = lineStart; pos < lines.Count; pos++)
            {
                var  line = lines[pos].Trim();
                Type foundType;
                Enum.TryParse(line, out foundType);

                if (foundType != Type.None && section.SectionType == Type.None)
                {
                    section.StartLine   = pos;
                    section.SectionType = foundType;
                }
                else if (foundType != Type.None && section.SectionType != Type.None)
                {
                    break;
                }
                else if (section.SectionType != Type.None && line.Length > 0)
                {
                    section.Lines.Add(line);
                    section.EndLine = pos;
                }
            }

            return(section.SectionType != Type.None ? section : null);
        }
Exemple #2
0
        public static SliceSection Parse(IList<string> lines, int lineStart)
        {
            var section = new SliceSection
            {
                Lines = new List<string>()
            };

            for (var pos = lineStart; pos < lines.Count; pos++)
            {
                var line = lines[pos].Trim();
                Type foundType;
                Enum.TryParse(line, out foundType);

                if (foundType != Type.None && section.SectionType == Type.None)
                {
                    section.StartLine = pos;
                    section.SectionType = foundType;
                }
                else if (foundType != Type.None && section.SectionType != Type.None)
                {
                    break;
                }
                else if (section.SectionType != Type.None && line.Length > 0)
                {
                    section.Lines.Add(line);
                    section.EndLine = pos;
                }
            }

            return section.SectionType != Type.None ? section : null;
        }
Exemple #3
0
        public void Write(SliceSection section, StringBuilder sb)
        {
            if (section.SectionType == SliceSection.Type.FROM)
            {
                foreach (var line in section.Lines)
                {
                    sb.Append("FROM ").AppendLine(line);
                }
            }

            if (section.SectionType == SliceSection.Type.RUN)
            {
                var text = string.Join($" && {"\\"} {Environment.NewLine}", section.Lines);
                sb.Append("RUN ");
                sb.AppendLine(text);
            }
        }
Exemple #4
0
        public void Write(SliceSection section, StringBuilder sb)
        {
            if (section.SectionType == SliceSection.Type.OS)
            {
                foreach (var line in section.Lines)
                {
                    sb.AppendLine("# " + line);
                }
            }

            if (section.SectionType == SliceSection.Type.RUN)
            {
                foreach (var line in section.Lines)
                {
                    sb.AppendLine(line);
                }
            }
        }
Exemple #5
0
        public Slice(SemName semName, IList <string> lines)
        {
            SemName    = semName;
            SemVersion = new SemVersion(semName.VersionPart, semName.PreReleasePart);
            Sections   = new List <SliceSection>();
            OsList     = new List <string>();

            int          lineStart = 0;
            SliceSection section;

            while ((section = SliceSection.Parse(lines, lineStart)) != null)
            {
                lineStart = section.EndLine > lineStart ? section.EndLine : lineStart + 1;
                Sections.Add(section);
            }

            foreach (var s in Sections.Where(s => s.SectionType == SliceSection.Type.OS))
            {
                foreach (var line in s.Lines.Where(l => !l.StartsWith("#")))
                {
                    OsList.Add(new SemName(line.Trim()).NamePart.ToLower());
                }
            }
        }