예제 #1
0
bool stri_equal::operator()(const nxsstring& x, const nxsstring& y) const
{
   nxsstring::const_iterator px = x.begin();
   nxsstring::const_iterator py = y.begin();
   while( px != x.end() && py != y.end() ) {
      if( toupper(*px) != toupper(*py) ) return false;
      ++px;
      ++py;
   }

   return ( x.size() == y.size() ) ? true : false;
}
예제 #2
0
/**
 * @method Equals [bool:public]
 * @param s [nxsstring] the comparison string
 * @param respect_case [bool] determines whether or not comparison is case sensitive (default is false)
 *
 * Returns true if token nxsstring exactly equals s.  The comparison
 * is case insensitive by default.  If abbreviations are to be allowed,
 * either Begins or Abbreviation should be used instead of Equals.
 */
bool NexusToken::Equals( nxsstring s, bool respect_case /* = false */ )
{
	int k;
	char tokenChar, otherChar;

	int slen = s.size();
	if( slen != token.size() )
		return false;

	for( k = 0; k < token.size(); k++ )
	{
      if( respect_case ) {
         tokenChar = token[k];
         otherChar = s[k];
      }
      else {
   		tokenChar = (char)toupper( token[k] );
   		otherChar = (char)toupper( s[k] );
      }
		if( tokenChar != otherChar )
			return false;
	}

	return true;
}
예제 #3
0
/**
 * @method Abbreviation [bool:public]
 * @param s [nxsstring] the comparison string
 *
 * Returns true if token begins with the capitalized portion of s
 * and, if token is longer than s, the remaining characters match
 * those in the lower-case portion of s.  The comparison is case
 * insensitive.  This function should be used instead of the 
 * Begins function if you wish to allow for abbreviations of commands
 * and also want to ensure that user does not type in a word that
 * does not correspond to any command.
 */
bool NexusToken::Abbreviation( nxsstring s )
{
	int k;
	int slen = s.size();
	int tlen = token.size();
	char tokenChar, otherChar;

	// The variable mlen refers to the "mandatory" portion
	// that is the upper-case portion of s
	//
	int mlen;
	for( mlen = 0; mlen < slen; mlen++ ) {
		if( !isupper(s[mlen]) )	break;
	}
	
	// User must have typed at least mlen characters in
	// for there to even be a chance at a match
	//
	if( tlen < mlen )
		return false;
	
	// If user typed in more characters than are contained in s,
	// then there must be a mismatch
	//
	if( tlen > slen )
		return false;
	
	// Check the mandatory portion for mismatches
	//
	for( k = 0; k < mlen; k++ )
	{
  		tokenChar = (char)toupper( token[k] );
  		otherChar = s[k];
		if( tokenChar != otherChar )
			return false;
	}
	
	// Check the auxiliary portion for mismatches (if necessary)
	//
	for( k = mlen; k < tlen; k++ )
	{
  		tokenChar = (char)toupper( token[k] );
  		otherChar = (char)toupper( s[k] );
		if( tokenChar != otherChar )
			return false;
	}

	return true;
}