Beispiel #1
0
static int valid(char *ciphertext, struct fmt_main *self)
{
	char *cp, *cp2;
	if (strncmp(ciphertext, FORMAT_TAG, TAG_LENGTH)) return 0;
	cp = ciphertext + TAG_LENGTH;
	if (*cp != '$') return 0;
	++cp;
	cp2 = strchr(cp, '$');
	if (!cp2) return 0;
	if (cp2-cp > 32) return 0;
	cp = &cp2[1];
	if (isDigits(cp) == 0) return 0;
	cp = strchr(cp, '$');
	if (!cp) return 0;
	++cp;
	if (isDigits(cp) == 0) return 0;
	cp = strchr(cp, '$');
	if (!cp) return 0;
	++cp;
	if (isDigits(cp) == 0) return 0;
	cp = strchr(cp, '$');
	if (!cp) return 0;
	++cp;
	if (isDigits(cp) == 0) return 0;
	cp = strchr(cp, '$');
	if (!cp) return 0;
	++cp;
	if (strlen(cp) != 88) return 0;
	return 1;
}
void Parser::matchDigits()
{
	if (isDigits()) {
		getToken();
	} else {
		throw ParseException(_stmtNum, _token, "Constant should contain only digits");
	}
}
Beispiel #3
0
Client::Client(const char *ip, const char *port)
{
  this->net = new QNetwork(this);
  if (!isDigits(port))
    throw std::string("Invalid Port");
  this->net->initServeur(ip, std::stoi(port));
  this->exec = new execCmd(this);
  this->connected = false;
  this->mainWin = new Mainwidget(this);
  this->loginWin = new login(this);
}
Beispiel #4
0
int GetIntVal(std::string strConvert) {
    try {
        if (isDigits(strConvert))
            return (atoi(strConvert.c_str())) * MILLI;

        return MILLI; //default value is ten hours
    } catch (...) {
        return MILLI; //default value is ten hours
    }

}
void ASTExpressionBuilder::buildOperands()
{
	ASTType type;

	if (isDigits()) {
		type = CONSTANT;
	} else if (isName()) {
		type = VARIABLE;
	}

	_results.push_back(new ASTNode(_token, type, 0));
}
ASTNode* ASTExpressionBuilder::shuntingYardAlgorithm()
{
	_operators.clear();
	_results.clear();

	while (!_tokens.empty()) {
		_token = _tokens.front();
		_tokens.pop_front();

		if (isKeyword("+") || isKeyword("-") || isKeyword("*") || isKeyword("/")) {
			while (!_operators.empty() && getOprPriority(_token) <= getOprPriority(_operators.back())) {				
				buildOperators();
			}

			_operators.push_back(_token);
		} else if (isKeyword("(")) {
			_operators.push_back("(");
		} else if (isKeyword(")")) {
			while (!_operators.empty() && _operators.back() != "(") {				
				buildOperators();
			}

			if (_operators.empty()) {
				throw ParseException(_token, "Mismatched parentheses");
			}

			_operators.pop_back();
		} else if (isDigits() || isName()) {
			buildOperands();
		} else {
			throw ParseException(_token, "Unable to parse expression");
		}

		getToken();
	}

	while (!_operators.empty()) {
		if (_operators.back() == "(") {
			throw ParseException(_token, "Mismatched parentheses");
		}

		buildOperators();
	}

	ASTNode* expNode = _results.back();
	_results.pop_back();

	return expNode;
}
Beispiel #7
0
std::string extractNumber(const std::string & value) {
    string sentence = value;
    stringstream extract; // extract words by words;

    extract << sentence; //enter the sentence that we want to extract word by word

    string word = "";

    //while there are words to extract
    while (!extract.fail()) {
        extract >> word; //extract the word

        if (isDigits(word)) {
            if (atoi(word.c_str()) > 399 && atoi(word.c_str()) < 554) //report only gridftp error codes			
                return word;
        }
    }
    return "";
}
std::list<std::string> Parser::getExpressionTokens()
{
	std::list<std::string> tokens;

	while (!isKeyword(";")) {
		if (isKeyword("(") || isKeyword(")") || isKeyword("+") || isKeyword("-") || isKeyword("*") || isKeyword("/")) {
			tokens.push_back(_token);
		} else if (isDigits()) {
			_constTable->addConstant(std::stoi(_token));

			tokens.push_back(_token);
		} else if (isName()) {
			_varTable->addVariable(_token);
			
			tokens.push_back(_token);
		} else {
			throw ParseException(_stmtNum, _token, "Unable to parse expression");
		}
		
		getToken();
	}

	return tokens;
}
 // check <real_number>
 bool isNum(string s) {
     s = removeMark(s);
     int p = s.find_first_of('.');
     if (p == -1) return !s.empty() && isDigits(s);
     else return s.size() > 1 && (isDigits(s.substr(0, p)) && isDigits(s.substr(p+1)));
 }
Beispiel #10
0
 // check <integer>
 bool isInt(string s) {
     s = removeMark(s);
     return !s.empty() && isDigits(s);
 }