Skip to content

Commit bf6e2d6

Browse files
committed
Corrected problem with code file trims
1 parent 9853672 commit bf6e2d6

1 file changed

Lines changed: 73 additions & 2 deletions

File tree

ZXBStudio/BuildSystem/ZXCodeFile.cs

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Avalonia.Svg.Skia;
2+
using System;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
@@ -116,7 +117,14 @@ public void CreateBuildFile(IEnumerable<ZXCodeFile> AllFiles)
116117
string line = lines[lineNum];
117118
string trim = line.Trim().ToLower();
118119

119-
if (trim.StartsWith("#line") || string.IsNullOrWhiteSpace(trim))
120+
if (string.IsNullOrWhiteSpace(trim))
121+
{
122+
sbSource.AppendLine(line);
123+
sb.AppendLine(line);
124+
continue;
125+
}
126+
127+
if (trim.StartsWith("#line"))
120128
continue;
121129

122130
if (regInclude.IsMatch(line))
@@ -156,8 +164,48 @@ public void CreateBuildFile(IEnumerable<ZXCodeFile> AllFiles)
156164

157165
BuildContent = sb.ToString();
158166

167+
bool doTrim = true;
168+
169+
while (doTrim)
170+
{
171+
BuildContent.TrimEnd();
172+
173+
if (BuildContent.EndsWith("\r") || BuildContent.EndsWith("\n"))
174+
{
175+
176+
if (BuildContent.EndsWith("\r\n"))
177+
BuildContent = BuildContent.Substring(0, BuildContent.Length - 2);
178+
else
179+
BuildContent = BuildContent.Substring(0, BuildContent.Length - 1);
180+
181+
}
182+
else
183+
doTrim = false;
184+
}
185+
159186
File.WriteAllText(Path.Combine(Directory, TempFileName), BuildContent);
187+
160188
Content = sbSource.ToString();
189+
190+
doTrim = true;
191+
192+
while (doTrim)
193+
{
194+
195+
Content.TrimEnd();
196+
197+
if (Content.EndsWith("\r") || Content.EndsWith("\n"))
198+
{
199+
200+
if (Content.EndsWith("\r\n"))
201+
Content = Content.Substring(0, Content.Length - 2);
202+
else
203+
Content = Content.Substring(0, Content.Length - 1);
204+
205+
}
206+
else
207+
doTrim = false;
208+
}
161209
}
162210
else
163211
{
@@ -171,7 +219,10 @@ public void CreateBuildFile(IEnumerable<ZXCodeFile> AllFiles)
171219
string trim = line.Trim().ToLower();
172220

173221
if (string.IsNullOrWhiteSpace(trim))
222+
{
223+
sb.AppendLine(line);
174224
continue;
225+
}
175226

176227
if (!inAsm)
177228
inAsm = line.Trim().ToLower().StartsWith("asm");
@@ -209,6 +260,26 @@ public void CreateBuildFile(IEnumerable<ZXCodeFile> AllFiles)
209260

210261
BuildContent = sb.ToString();
211262

263+
bool dotrim = true;
264+
265+
while (dotrim)
266+
{
267+
268+
BuildContent.TrimEnd();
269+
270+
if (BuildContent.EndsWith("\r") || BuildContent.EndsWith("\n"))
271+
{
272+
273+
if (BuildContent.EndsWith("\r\n"))
274+
BuildContent = BuildContent.Substring(0, BuildContent.Length - 2);
275+
else
276+
BuildContent = BuildContent.Substring(0, BuildContent.Length - 1);
277+
278+
}
279+
else
280+
dotrim = false;
281+
}
282+
212283
File.WriteAllText(Path.Combine(Directory, TempFileName), sb.ToString());
213284
}
214285
}

0 commit comments

Comments
 (0)