Esempio n. 1
0
// Given a string, turn it into a bitmask word
static Word string_to_bitmask(char const *p, unsigned const word_length)
{
	WordParser parser;

	while (*p != '\0')
		if (!parser.parse(*p++))
			return 0;
	return parser.result(word_length);
}
Esempio n. 2
0
// Parse a string in the form "<word> <matched>"
static bool parse_move(string const &cmd, unsigned const word_length, Word * const wordp, unsigned * const matchedp)
{
	WordParser parser;

	char const *p = cmd.c_str();
	for (;;) {
		if (*p == '\0')
			return false;
		if (*p == ' ' || *p == '\t')
			break;
		if (!parser.parse(*p++))
			return false;
	}
	*wordp = parser.result(word_length);
	if (*wordp == 0)
		return false;
	while (*p == ' ' || *p == '\t')
		p++;
	if (!isdigit(*p))
		return false;
	*matchedp = static_cast<unsigned>(atoi(p));
	return *matchedp <= word_length;
}