-
Notifications
You must be signed in to change notification settings - Fork 3
/
Block.cs
56 lines (47 loc) · 1.72 KB
/
Block.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace onscripter_helper
{
public class Block
{
public Block(String blockString, Int32 position)
{
this.OriginalText = blockString;
this.Position = position;
var engPhrasePattern = new Regex(@"`([^`]*)`[\\,@,/]");
var commentPattern = new Regex(@"^;(.*)$", RegexOptions.Multiline);
var engPhraseMatches = engPhrasePattern.Matches(blockString);
PhrasesEng = new List<Phrase>();
foreach (Match engPhraseMatch in engPhraseMatches)
{
PhrasesEng.Add(new Phrase
{
Position = engPhraseMatch.Index,
Text = engPhraseMatch.Groups[1].ToString()
});
}
if (PhrasesEng.Count > 0)
{
var commentMatches = commentPattern.Matches(blockString);
var commentStrings = (from object commentMatch in commentMatches select ((Match)commentMatch).Groups[1].ToString()).ToList();
Comments = new List<Comment>();
commentStrings.ForEach(c => Comments.Add(new Comment(c)));
}
}
public Int32 Position { get; set; }
public String OriginalText { get; set; }
public List<Phrase> PhrasesEng { get; set; }
public List<Comment> Comments { get; set; }
public List<String> PhrasesJp
{
get
{
var phrasesJp = new List<String>();
Comments.ForEach(c => phrasesJp.AddRange(c.JpPhrases));
return phrasesJp;
}
}
}
}