Esempio n. 1
0
 /// <summary>
 /// Split a string by line breaks.
 /// </summary>
 /// <param name="source">
 /// The string to split.
 /// </param>
 /// <returns>
 /// The split strings.
 /// </returns>
 private static IEnumerable <string> SplitByLineBreaks(string source)
 {
     return(LineRegex
            .Matches(source)
            .Cast <Match>()
            .Select(x => x.Value));
 }
        public IniPropertyData(string existingText) : base(IniLineType.Property, existingText)
        {
            var matches = LineRegex.Matches(existingText);

            Key   = matches[0].Groups[1].Value.Trim();
            Value = matches[0].Groups[2].Value.Trim();
        }
Esempio n. 3
0
            override public string ToString()
            {
                try
                {
                    var line = LineRegex.Replace(Lines[0].ToString(), "\r\n|\t");
                    var match = DateTimeRegex.Match(line);

                    if (match.Success)
                        line = match.Groups[3].Value;

                    sb.AppendFormat("{0}\r\n", line); //首行

                    for (var i = 1; i < Lines.Length; ++i)  //从第二行开始
                    {
                        var other = Lines[i].ToString();
                        sb.AppendFormat("|\t{0}\r\n", LineRegex.Replace(other, "\r\n|\t"));
                    }

                    string ret = sb.ToString();
                    sb.Remove(0, sb.Length);
                    return ret;
                }
                catch (System.Exception e)
                {
                    return "Log ToString Error" + e;
                }
            }
Esempio n. 4
0
        private IniCommentData(string textOrLine, bool isLine) : base(IniLineType.Comment, isLine ? textOrLine : null)
        {
            if (string.IsNullOrWhiteSpace(textOrLine))
            {
                throw new System.ArgumentException("message", nameof(textOrLine));
            }

            if (isLine)
            {
                var matches = LineRegex.Matches(textOrLine);
                Text = matches[0].Groups[1].Value.Trim();
            }
            else
            {
                Text = textOrLine;
            }
        }
        public static FunctionStackInfo Create(string suFileLine)
        {
            if (!LineRegex.IsMatch(suFileLine))
            {
                throw new ArgumentException($"Line '{ suFileLine }' does not match SU file line", nameof(suFileLine));
            }

            var matches = LineRegex.Match(suFileLine);

            var file      = matches.Groups[1].Value;
            var line      = uint.Parse(matches.Groups[2].Value);
            var column    = uint.Parse(matches.Groups[3].Value);
            var name      = matches.Groups[4].Value;
            var bytes     = uint.Parse(matches.Groups[5].Value);
            var qualifier = ParseQualifier(matches.Groups[6].Value.Trim());

            return(Create(file, name, line, column, bytes, qualifier));
        }
        public static FunctionStackInfo Create(LineInstance suFileLine)
        {
            if (!LineRegex.IsMatch(suFileLine.Line))
            {
                throw new ArgumentException($"Line '{ suFileLine }' does not match SU file line", nameof(suFileLine));
            }

            var matches = LineRegex.Match(suFileLine.Line);

            var file      = matches.Groups[1].Value;
            var line      = uint.Parse(matches.Groups[2].Value);
            var column    = uint.Parse(matches.Groups[3].Value);
            var name      = matches.Groups[4].Value;
            var bytes     = uint.Parse(matches.Groups[5].Value);
            var qualifier = ParseQualifier(matches.Groups[6].Value.Trim());

            return(Create(Path.Combine(Path.GetDirectoryName(suFileLine.FileName), file).Replace("\\Debug\\", "\\"), name, line, column, bytes, qualifier));
        }
Esempio n. 7
0
        // ------ Ini Deserialization ------

        /// <summary>
        /// Load the values in an Ini file into this value store instance,
        /// replacing the value store's contents.
        /// </summary>
        public static void Load(ValueStore store, string content)
        {
            // TODO: More input validation
            var lines = content.Split('\n');

            foreach (var line in lines)
            {
                if (commentedLineRegex.IsMatch(line) || line.Trim().Length == 0)
                {
                    continue;
                }

                var match = LineRegex.Match(line);
                if (!match.Success)
                {
                    Debug.LogWarning("Failed to read line in Ini file: " + line);
                    continue;
                }

                // Groups:
                // 1 = Regular Name
                // 2 = Child name
                // 3 = Quoted Parameter
                // 4 = Unquoted Parameter
                // 5 = Quoted Value
                // 6 = Unquoted Value

                var rootCapture = match.Groups[1];
                var rootNode    = store.GetOrCreateRoot(rootCapture.Value);

                var node = GetNodeRecursive(rootNode, match, rootCapture.Index + rootCapture.Length - 1);

                var isQuoted     = true;
                var valueCapture = match.Groups[5];
                if (!valueCapture.Success)
                {
                    isQuoted     = false;
                    valueCapture = match.Groups[6];
                }

                node.value = ProcessQuotedString(valueCapture.Value, isQuoted);
            }
        }
        private IniSectionData(string nameOrLine, bool isLine) : base(IniLineType.SectionHeader, isLine ? nameOrLine : null)
        {
            if (string.IsNullOrWhiteSpace(nameOrLine))
            {
                throw new ArgumentException("message", nameof(nameOrLine));
            }

            if (isLine)
            {
                var matches = LineRegex.Matches(nameOrLine);
                Name = matches[0].Groups[1].Value;
            }
            else
            {
                Name = nameOrLine;
            }

            AddLine(this);
        }
Esempio n. 9
0
        public void Parse()
        {
            if (Lines.Count > 0)
            {
                // First line
                var matchFirstLine = LineRegex.Match(Lines.First());
                if (matchFirstLine.Success)
                {
                    var date = matchFirstLine.Groups["date"].ToString();
                    var time = matchFirstLine.Groups["time"].ToString();

                    TimeStamp = CreateTimeStamp(date: date, time: time);
                    Level     = matchFirstLine.Groups["level"].ToString();
                    var data = matchFirstLine.Groups["data"].ToString();

                    var matchTypeAndData = TypeRegex.Match(data);
                    if (matchTypeAndData.Success)
                    {
                        Type = matchTypeAndData.Groups["type"].ToString();
                        Data = matchTypeAndData.Groups["data"].ToString();
                    }
                    else
                    {
                        Type = "undefined";
                        Data = data;
                    }
                }

                foreach (var line in Lines.Skip(1))
                {
                    var matchLine = LineRegex.Match(line);
                    if (matchLine.Success)
                    {
                        var data = matchLine.Groups["data"].ToString();
                        Data += data;
                    }
                }
            }

            Parsed = true;
        }
Esempio n. 10
0
        protected override IList <string> SplitToLines(string serialized)
        {
            _sideboardIndicator = getSideboardIndicator(serialized);

            var lines = serialized.Trim().Split(Array.From("\r\n", "\r", "\n"), StringSplitOptions.None);

            var result = new List <string>();

            foreach (string line in lines)
            {
                var match = LineRegex.Match(line);

                if (line == string.Empty)
                {
                    if (result.Count > 0 && result[result.Count - 1] != string.Empty)
                    {
                        result.Add(line);
                    }
                }
                else if (isSideboardIndicator(line))
                {
                    result.Add(line);
                }
                else if (match.Success)
                {
                    result.Add(line);
                }
                else if (isKnownMtgoName(line.Trim()))
                {
                    result.Add("1 " + line.Trim());
                }
                else if (line.IndexOf("\t", Str.Comparison) >= 0)
                {
                    var parts = line.Split(Array.From('\t'), StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < parts.Length; i++)
                    {
                        if (isKnownMtgoName(parts[i]))
                        {
                            if (i > 0 && parts[i - 1].All(char.IsDigit))
                            {
                                result.Add(parts[i - 1] + ' ' + parts[i]);
                            }
                            else if (i < parts.Length - 1 && parts[i + 1].All(char.IsDigit))
                            {
                                result.Add(parts[i + 1] + ' ' + parts[i]);
                            }
                            break;
                        }
                    }
                }
                else
                {
                    var splits = _splitterRegex.Matches(line)
                                 .OfType <Match>()
                                 .Select(m => m.Index)
                                 .ToList();

                    if (splits.Count > 0)
                    {
                        splits.Add(line.Length);
                    }

                    for (int i = 0; i < splits.Count - 1; i++)
                    {
                        string substring = line.Substring(splits[i], splits[i + 1] - splits[i]).TrimEnd();

                        var substringMatch = LineRegex.Match(substring);
                        if (substringMatch.Success)
                        {
                            result.Add(substring);
                        }
                    }
                }
            }

            return(result);
        }