Exemple #1
0
static bool IsPalindrome(string str)
{
    int len;

    len = StringLength(str);
    if (len <= 1) {
        return (TRUE);
    } else {
        return (IthChar(str, 0) == IthChar(str, len - 1)
                && IsPalindrome(SubString(str, 1, len - 2)));
    }
}
Exemple #2
0
static bool IsLegalWord(string token)
{
    int i;

    for (i = 0; i < StringLength(token); i++) {
        if (!isalpha(IthChar(token, i))) return (FALSE);
    }
    return (TRUE);
}
Exemple #3
0
static int FindFirstVowel(string word)
{
    int i;

    for (i = 0; i < StringLength(word); i++) {
        if (IsVowel(IthChar(word, i))) return (i);
    }
    return (-1);
}
Exemple #4
0
static void skipWhitespaceCharacters(void)
	{
	if(skipWhitespace) /* Do we have to skip? */
		{
		/* Skip characters as long as whitespace is found: */
		while(cpos < buflen && isspace(IthChar(buffer, cpos)))
			++cpos;
		}
	}
Exemple #5
0
string GetNextToken(void)
	{
	char ch;
	int start;
	string result;
	
	/* Check for error condition: */
	if(cpos >= buflen)
		Error("No more tokens");
	
	/* Depending on the package mode, we have to skip
	   whitespace characters: */
	skipWhitespaceCharacters();

	/* Retrieve the next character: */
	ch = IthChar(buffer, cpos);
	
	/* Based on that character, either scan a string or return the character: */
	if(isalnum(ch)) /* Character is alphanumeric: */
		{
		/* Remember the start of the string: */
		start = cpos;
		
		/* Iterate until a non-alphanumeric character is encountered: */
		while(cpos < buflen && isalnum(IthChar(buffer, cpos)))
			++cpos;
		
		/* Return the substring from start to the current character position: */
		result = SubString(buffer, start, cpos - 1);
		}
	else /* Character is not alphanumeric: */
		{
		++cpos;
		result = CharToString(ch);
		}
	
	/* Depending on the package mode, we have to skip
	   whitespace characters again: */
	skipWhitespaceCharacters();

	return result;
	}