8
8
using System . Collections . Generic ;
9
9
using Beats2 . Data ;
10
10
using System ;
11
+ using System . IO ;
12
+ using System . Text ;
11
13
12
14
namespace Beats2 . Parser
13
15
{
@@ -35,24 +37,12 @@ public override void LoadMetadata()
35
37
Logger . Warn ( TAG , "Metadata was already previously loaded, reloading..." ) ;
36
38
}
37
39
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 ) ;
56
46
}
57
47
}
58
48
@@ -77,6 +67,41 @@ public override void LoadCharts()
77
67
// TODO: Load from _notesData, then add _events
78
68
}
79
69
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
+
80
105
private void ParseTag ( string tag , string value )
81
106
{
82
107
switch ( tag . ToUpper ( ) ) {
0 commit comments