Commit 84486e35 authored by Alvarez, Gonzalo's avatar Alvarez, Gonzalo
Browse files

OneOperatorSpec: check for missing * in expressions

parent 9a52bede
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
#ifndef ONEOPERATORSPEC_H
#define ONEOPERATORSPEC_H
#include "Vector.h"
#include "PsimagLite.h"
#include <cstdlib>

namespace PsimagLite {
@@ -29,7 +30,14 @@ struct OneOperatorSpec {
			err("WRONG op. spec. " + label_ + ", nothing after ?\n");

		label = label_.substr(0, i);
		dof = atoi(label_.substr(i + 1, label_.length()).c_str());
		const String numericString = label_.substr(i + 1, label_.length());
		if (!isAnInteger(numericString)) {
			throw RuntimeError("FATAL: Syntax Error: The label " + label +
			                   " must be followed by an integer " +
			                   "and not " + numericString + "\n");
		}

		dof = atoi(numericString.c_str());
	}

	struct SiteSplit {
+11 −0
Original line number Diff line number Diff line
@@ -69,6 +69,17 @@ int atoi(String str)
	return std::atoi(str.c_str());
}

bool isAnInteger(String str)
{
	const SizeType n = str.length();
	for (SizeType i = 0; i < n; ++i) {
		if (isdigit(str[i])) continue;
		return false;
	}

	return true;
}

bool isAfloat(String str)
{
	const SizeType n = str.length();
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ SizeType log2Integer(SizeType x);

bool isAfloat(String str);

bool isAnInteger(String str);

int atoi(String);

double atof(String);