Skip to content

Commit 5db4c02

Browse files
committed
Make include conversion whitespace follow the style of the project.
1 parent 81bc9ec commit 5db4c02

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

dstep/driver/Application.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ private:
133133
if (arguments.rawArgs.any!((string e) => e == "-ObjC"))
134134
handleObjectiveC();
135135

136-
if( arguments["import-prefix"].hasValue )
137-
handleAutoImportPrefix(arguments["import-prefix"].value);
136+
if (arguments["import-prefix"].hasValue)
137+
handleAutoImportPrefix(arguments["import-prefix"].value);
138138

139-
if( arguments["import-filter"].hasValue )
140-
handleAutoImportFilter(arguments["import-filter"].value);
139+
if (arguments["import-filter"].hasValue)
140+
handleAutoImportFilter(arguments["import-filter"].value);
141141
}
142142

143143
void handleObjectiveC ()

dstep/translator/IncludeHandler.d

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ class IncludeHandler
3030
{
3131
private string[] rawIncludes;
3232
private string[] imports;
33+
3334
// True if includes should be converted to imports.
3435
private bool convertIncludes = false;
36+
3537
// Includes matching this will be converted to imports.
3638
private Regex!char convertableIncludePattern = regex(".*");
39+
3740
// Prefix for auto generated imports.
3841
private string importPrefix = "";
3942

@@ -121,13 +124,15 @@ class IncludeHandler
121124
}
122125

123126
/// Makes includes that match regex filter be converted to import with prefix.
124-
void setAutoImportPrefix(string prefix){
127+
void setAutoImportPrefix (string prefix)
128+
{
125129
this.convertIncludes = true;
126130
this.importPrefix = prefix;
127131
}
128132

129133
/// Makes includes that match regex filter be converted to import with prefix.
130-
void setAutoImportFilter(string filter){
134+
void setAutoImportFilter (string filter)
135+
{
131136
this.convertIncludes = true;
132137
this.convertableIncludePattern = regex(filter);
133138
}
@@ -139,7 +144,6 @@ class IncludeHandler
139144
return toImport(i);
140145
else if( this.convertIncludes && isConvertableInclude(e) )
141146
return toImport(autoConvertInclude(e));
142-
143147
else
144148
return "";
145149
})(rawIncludes);
@@ -149,6 +153,13 @@ class IncludeHandler
149153
return r.append(imps).filter!(e => e.any).unique.toArray;
150154
}
151155

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+
152163
private:
153164

154165
string toImport (string str)
@@ -167,17 +178,15 @@ private:
167178
}
168179

169180
/// Checks if the given include file name should be converted to an import declaration.
170-
bool isConvertableInclude(string include)
181+
bool isConvertableInclude (string include)
171182
{
172183
return cast(bool)(matchFirst(include, convertableIncludePattern));
173184
}
174185

186+
175187
/// Generates an importable module name from an include file name.
176188
string autoConvertInclude(string include)
177189
{
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);
182191
}
183192
}

0 commit comments

Comments
 (0)