diff --git a/source/workspaced/dparseext.d b/source/workspaced/dparseext.d index cdb3830..99b9971 100644 --- a/source/workspaced/dparseext.d +++ b/source/workspaced/dparseext.d @@ -415,3 +415,23 @@ unittest assert(getIfElse(p("if (x) {} else if (y) {} else {}")) !is null); assert(cast(IfStatement)getIfElse(p("if (x) {} else if (y) {} else {}")) is null); } + +C[] substr(C)(C[] s, size_t[2] range) +{ + return substr(s, range[0], range[1]); +} + +C[] substr(C)(C[] s, size_t start, size_t end) +{ + if (!s.length) + return s; + if (start < 0) + start = 0; + if (start >= s.length) + start = s.length - 1; // @suppress(dscanner.suspicious.length_subtraction) + if (end > s.length) + end = s.length; + if (end < start) + return s[start .. start]; + return s[start .. end]; +} diff --git a/source/workspaced/visitors/methodfinder.d b/source/workspaced/visitors/methodfinder.d index 8d1cb15..047e0cc 100644 --- a/source/workspaced/visitors/methodfinder.d +++ b/source/workspaced/visitors/methodfinder.d @@ -130,6 +130,12 @@ struct InterfaceDetails size_t[2] blockRange; /// A (name-based) sorted set of referenced types with first occurences of every type or alias not including built-in types, but including object.d types and aliases. ReferencedType[] referencedTypes; + + /// Returns true if there are no non-whitespace characters inside the block. + bool isEmpty() const + { + return !code.substr(blockRange).strip.length; + } } class InterfaceMethodFinder : AttributesVisitor