Commit 807d1621 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

PredicateAwesome with replacement for constants

parent 6daee7fd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ int main(int argc, char** argv)
	if (argc < 3) return 1;
	PsimagLite::String predicate(argv[1]);

	PsimagLite::PredicateAwesome<>::replaceAll(predicate, "c", "5");
	PsimagLite::PredicateAwesome<> pAwesome(predicate);
	std::cout<<pAwesome.isTrue("l", atoi(argv[2]));
}
+18 −0
Original line number Diff line number Diff line
@@ -84,6 +84,24 @@ public:
		return false;
	}

	template<typename T1, typename T2>
	bool isTrue(String name1, T1 val1, String name2, T2 val2)
	{
		return (isTrue(name1, val1) && isTrue(name2, val2));
	}

	static void replaceAll(String& str, const String& from, const String& to)
	{
		if (from.empty()) return;

		size_t start_pos = 0;

		while ((start_pos = str.find(from, start_pos)) != String::npos) {
			str.replace(start_pos, from.length(), to);
			start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
		}
	}

private:

	String pred_;