diff --git a/source/dub/dub.d b/source/dub/dub.d index 5226a79..f1f213e 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -734,6 +734,9 @@ */ string getModuleNameFromContent(string content) { import std.regex; + import std.string; + + if(content.strip == "") return ""; static bool regex_initialized = false; static Regex!char comments_pattern, module_pattern; @@ -745,17 +748,23 @@ } content = replaceAll(content, comments_pattern, ""); - string moduleName = matchFirst(content, module_pattern).front; - + auto result = matchFirst(content, module_pattern); + + string moduleName; + if(!result.empty) moduleName = result.front; + if (moduleName.length >= 7) moduleName = moduleName[7..$-1]; - + return moduleName; } unittest { - import std.stdio; + //test empty string + string name = getModuleNameFromContent(""); + assert(name == "", "can't get module name from empty string"); + //test simple name - string name = getModuleNameFromContent("module myPackage.myModule;"); + name = getModuleNameFromContent("module myPackage.myModule;"); assert(name == "myPackage.myModule", "can't parse module name"); //test if it can ignore module inside comments @@ -778,6 +787,7 @@ string getModuleNameFromFile(string filePath) { string fileContent = filePath.readText; + logDiagnostic("Get module name from path: ", filePath); return getModuleNameFromContent(fileContent); } diff --git a/source/dub/version_.d b/source/dub/version_.d index 8947c5e..a4091b7 100644 --- a/source/dub/version_.d +++ b/source/dub/version_.d @@ -1,3 +1,3 @@ -module dub.version_; -enum dubVersion = "v0.9.22"; -enum initialCompilerBinary = "dmd"; +module dub.version_; +enum dubVersion = "v0.9.22-80-gc815ccf"; +enum initialCompilerBinary = "dmd";