Skip to content

Commit 5f9599a

Browse files
committed
Ignore comment lines in ParserSM
1 parent a8f9858 commit 5f9599a

File tree

1 file changed

+43
-18
lines changed

1 file changed

+43
-18
lines changed

beats2/Assets/Scripts/Parser/ParserSM.cs

+43-18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using System.Collections.Generic;
99
using Beats2.Data;
1010
using System;
11+
using System.IO;
12+
using System.Text;
1113

1214
namespace Beats2.Parser
1315
{
@@ -35,24 +37,12 @@ public override void LoadMetadata()
3537
Logger.Warn(TAG, "Metadata was already previously loaded, reloading...");
3638
}
3739

38-
// If performance becomes an issue (due to memory copying),
39-
// replace String.Split with a String.indexOf implementation
40-
string[] sections = LoadData().Split('#');
41-
foreach (string section in sections) {
42-
if (!string.IsNullOrEmpty(section)) {
43-
// Clean up and ignore comment lines
44-
string sectionCleaned = section.Trim();
45-
int indexEnd = sectionCleaned.IndexOf(';');
46-
if (indexEnd > 0) {
47-
sectionCleaned = sectionCleaned.Substring(0, indexEnd);
48-
}
49-
50-
string tag, value;
51-
if (ParseSection(sectionCleaned, ":", out tag, out value) &&
52-
!string.IsNullOrEmpty(tag) &&
53-
!string.IsNullOrEmpty(value)) {
54-
ParseTag(tag, value);
55-
}
40+
foreach (string section in LoadSections()) {
41+
string tag, value;
42+
if (ParseSection(section, ":", out tag, out value) &&
43+
!string.IsNullOrEmpty(tag) &&
44+
!string.IsNullOrEmpty(value)) {
45+
ParseTag(tag, value);
5646
}
5747
}
5848

@@ -77,6 +67,41 @@ public override void LoadCharts()
7767
// TODO: Load from _notesData, then add _events
7868
}
7969

70+
private List<string> LoadSections()
71+
{
72+
List<string> sections = new List<string>();
73+
StringBuilder buffer = new StringBuilder();
74+
75+
using (StringReader reader = new StringReader(LoadData())) {
76+
// Remove all comment lines and empty lines
77+
String line;
78+
while ((line = reader.ReadLine()) != null) {
79+
line = line.Trim();
80+
if (line.Length > 0 && !line.StartsWith("//")) {
81+
buffer.Append(line);
82+
}
83+
}
84+
85+
// If performance becomes an issue (due to memory copying),
86+
// replace String.Split with a String.indexOf implementation
87+
string[] sectionsRaw = buffer.ToString().Split('#');
88+
foreach (string sectionRaw in sectionsRaw) {
89+
if (!string.IsNullOrEmpty(sectionRaw)) {
90+
string section = sectionRaw.Trim();
91+
int indexEnd = section.IndexOf(';');
92+
if (indexEnd > 0) {
93+
section = section.Substring(0, indexEnd);
94+
}
95+
if (section.Length > 0) {
96+
sections.Add(section);
97+
}
98+
}
99+
}
100+
}
101+
102+
return sections;
103+
}
104+
80105
private void ParseTag(string tag, string value)
81106
{
82107
switch (tag.ToUpper()) {

0 commit comments

Comments
 (0)