-
Notifications
You must be signed in to change notification settings - Fork 1
/
extracts-faq-links.dart
48 lines (41 loc) · 1.38 KB
/
extracts-faq-links.dart
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
import 'dart:io';
import 'dart:async';
Future<List<String>> extractFAQLinks(String filePath) async {
// Define the list to hold the matches
List<String> faqLinks = [];
// Define a regular expression to match the desired pattern
// This regex looks for strings that start with /FAQ and end before a space
RegExp exp = RegExp(r'/Menu_Contributions[^ ]*');
try {
// Read the file line by line
await File(filePath).readAsLines().then((lines) {
for (var line in lines) {
// Find all matches in the current line
var matches = exp.allMatches(line);
for (var match in matches) {
// Add the matched string to the list
faqLinks.add(match.group(0)!);
}
}
});
} catch (e) {
print('An error occurred while reading the file: $e');
}
return faqLinks;
}
void printAsDartList(List<String> items) {
// Manually building the string representation of a Dart list
String listRepresentation = '';
for (int i = 0; i < items.length; i++) {
// Append the item with quotes
listRepresentation += '\'https://wiki.eclipse.org/${items[i]}\'' + (', \n');
}
listRepresentation += '';
// Print the manually formatted string
print(listRepresentation);
}
void main() async {
String filePath = './input/Menu_Contributions.md';
List<String> faqLinks = await extractFAQLinks(filePath);
printAsDartList(faqLinks);
}