41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace GameOfLife.IO
|
|
{
|
|
public class RlePatternMetaData : PatternMetadata
|
|
{
|
|
public RlePatternMetaData(string line, IEnumerable<string> comments)
|
|
{
|
|
Comments = comments.ToArray();
|
|
|
|
var mdLine = Regex.Replace(line, @"\s+", "");
|
|
var props = mdLine.Split(',');
|
|
if (props.Length < 2)
|
|
throw new ArgumentException("Line does not contain two properties");
|
|
|
|
var mp = new Regex(@"(\w+)=(.*)");
|
|
foreach (var prop in props)
|
|
{
|
|
var capture = mp.Match(prop).Groups;
|
|
var name = capture[1].Value;
|
|
var val = capture[2].Value;
|
|
switch (name)
|
|
{
|
|
case "x":
|
|
Width = int.Parse(val);
|
|
break;
|
|
case "y":
|
|
Height = int.Parse(val);
|
|
break;
|
|
// TODO: decode the rules
|
|
case "rules":
|
|
Rules = val;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |