added regex for parsing conditions and toggles from hrefs

This commit is contained in:
Rudis Muiznieks 2014-06-29 23:30:40 -05:00
parent 5f995fe06d
commit e9c7d4c391
2 changed files with 24 additions and 7 deletions

View File

@ -64,6 +64,19 @@
return story;
}
private void ParseHref(string href, out IList<string> conditions, out IList<string> toggles)
{
var match = RegexLib.Href.Match(href);
if (match.Success)
{
var cstr = match.Groups["conditions"].Value;
var tstr = match.Groups["toggles"].Value;
}
else throw new FormatException(string.Format("Invalid href: {0}", href));
conditions = null;
toggles = null;
}
private Scene BlockToScene(Block block)
{
var scene = new Scene
@ -75,11 +88,12 @@
if (sceneName.Success)
{
scene.Name = sceneName.Groups["text"].Value;
IList<string> conditions, toggles;
ParseHref(sceneName.Groups["href"].Value, out conditions, out toggles);
scene.Conditions = conditions;
scene.Toggles = toggles;
}
else
{
scene.Name = block.Name;
}
else scene.Name = block.Name;
return scene;
}

View File

@ -5,9 +5,12 @@
internal static class RegexLib
{
public static Regex Anchors = new Regex(string.Format(@"(?<anchor>\[(?<text>{0})\]\([ ]*(?<href>{1})[ ]*\))",
GetNestedBracketsPattern(), GetNestedParensPattern()),
RegexOptions.Singleline | RegexOptions.Compiled);
public static Regex Anchors =
new Regex(
string.Format(@"(?<anchor>\[(?<text>{0})\]\([ ]*(?<href>{1})[ ]*\))", GetNestedBracketsPattern(),
GetNestedParensPattern()), RegexOptions.Singleline | RegexOptions.Compiled);
public static Regex Href = new Regex(@"^(\?(?<conditions>[^#]+))?(#(?<toggles>.+))?$", RegexOptions.Compiled);
private const int _nestDepth = 6;