-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComment.cs
36 lines (35 loc) · 1.29 KB
/
Comment.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
namespace YuchikiML {
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using Sprache;
public static class CommentProcessor {
public static string DeleteComments(string source) {
var builder = new StringBuilder();
var first = 0;
var current = 0;
while (current < source.Length - 1) {
if (source[current] == '/' && source[current + 1] == '/') {
builder.Append(source, first, current - first);
current += 2;
while (source[current] != '\n') current++;
builder.Append('\n');
current++;
first = current;
} else if (source[current] == '(' && source[current + 1] == '*') {
builder.Append(source, first, current - first);
current += 2;
while (source[current] != '*' || source[current + 1] != ')') current++;
current += 2;
first = current;
} else {
current++;
}
}
builder.Append(source, first, current - first);
return builder.ToString();
}
}
}