// Copyright (c) 2014, Matthew Brennan Jones // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) module analysis.helpers; import std.string; import std.traits; import std.d.ast; S between(S)(S value, S before, S after) if (isSomeString!S) { return value.after(before).before(after); } S before(S)(S value, S separator) if (isSomeString!S) { auto i = indexOf(value, separator); if (i == -1) return value; return value[0 .. i]; } S after(S)(S value, S separator) if(isSomeString!S) { auto i = indexOf(value, separator); if( i == -1) return ""; size_t start = i + separator.length; return value[start .. $]; } S afterLast(S)(S value, S separator) if (isSomeString!S) { size_t i = rindex(value, separator); if (i == value.length) return ""; size_t start = i + separator.length; return value[start .. $]; } void shouldWarn(string code, analysis.run.AnalyzerCheck analyzers, string file=__FILE__, size_t line=__LINE__) { import analysis.run; // Run the code and get any warnings string[] rawWarnings = analyze("test", cast(ubyte[]) code, analyzers); string[] codeLines = code.split("\n"); // Get the warnings ordered by line string[size_t] warnings; for (size_t i=0; i