@@ -30,10 +30,13 @@ class IncludeHandler
30
30
{
31
31
private string [] rawIncludes;
32
32
private string [] imports;
33
+
33
34
// True if includes should be converted to imports.
34
35
private bool convertIncludes = false ;
36
+
35
37
// Includes matching this will be converted to imports.
36
38
private Regex! char convertableIncludePattern = regex(" .*" );
39
+
37
40
// Prefix for auto generated imports.
38
41
private string importPrefix = " " ;
39
42
@@ -121,13 +124,15 @@ class IncludeHandler
121
124
}
122
125
123
126
// / Makes includes that match regex filter be converted to import with prefix.
124
- void setAutoImportPrefix (string prefix){
127
+ void setAutoImportPrefix (string prefix)
128
+ {
125
129
this .convertIncludes = true ;
126
130
this .importPrefix = prefix;
127
131
}
128
132
129
133
// / Makes includes that match regex filter be converted to import with prefix.
130
- void setAutoImportFilter (string filter){
134
+ void setAutoImportFilter (string filter)
135
+ {
131
136
this .convertIncludes = true ;
132
137
this .convertableIncludePattern = regex(filter);
133
138
}
@@ -139,7 +144,6 @@ class IncludeHandler
139
144
return toImport (i);
140
145
else if ( this .convertIncludes && isConvertableInclude(e) )
141
146
return toImport (autoConvertInclude(e));
142
-
143
147
else
144
148
return " " ;
145
149
})(rawIncludes);
@@ -149,6 +153,13 @@ class IncludeHandler
149
153
return r.append(imps).filter! (e => e.any).unique.toArray;
150
154
}
151
155
156
+ // / Returns the base name (last component without extension) of a file path.
157
+ static string baseName (string path)
158
+ {
159
+ string last_component = text(retro(Path.pathSplitter(path)).front);
160
+ return Path.stripExtension( last_component );
161
+ }
162
+
152
163
private :
153
164
154
165
string toImport (string str)
@@ -167,17 +178,15 @@ private:
167
178
}
168
179
169
180
// / Checks if the given include file name should be converted to an import declaration.
170
- bool isConvertableInclude (string include)
181
+ bool isConvertableInclude (string include)
171
182
{
172
183
return cast (bool )(matchFirst(include, convertableIncludePattern));
173
184
}
174
185
186
+
175
187
// / Generates an importable module name from an include file name.
176
188
string autoConvertInclude (string include)
177
189
{
178
- string last_component = text(retro(Path.pathSplitter(include)).front);
179
- string pure_name = Path.stripExtension( last_component );
180
-
181
- return this .importPrefix ~ pure_name;
190
+ return this .importPrefix ~ baseName(include);
182
191
}
183
192
}
0 commit comments