示例#1
0
bool ParenMatcher::match( QTextCursor *cursor )
{
    if ( !enabled )
	return FALSE;
    bool ret = FALSE;

    QChar c( cursor->paragraph()->at( cursor->index() )->c );
    bool ok1 = FALSE;
    bool ok2 = FALSE;
    if ( c == '{' || c == '(' || c == '[' ) {
	ok1 = checkOpenParen( cursor );
	ret = ok1 || ret;
    } else if ( cursor->index() > 0 ) {
	c = cursor->paragraph()->at( cursor->index() - 1 )->c;
	if ( c == '}' || c == ')' || c == ']' ) {
	    ok2 = checkClosedParen( cursor );
	    ret = ok2 || ret;
	}
    }

    return ret;
}
示例#2
0
int checkSpecialToken(char* parsedFile, char c, int initSize)
{
  if(c != '&' && c != '|' && c != ';' && c != '(' && c != ')')
  {
    error(1, 0, "Improper call to checkSpecialToken");
    return 0;
  }

  if(c == '(')
  {
    return checkOpenParen(parsedFile, c, initSize);
  }

  if(c == ')')
  {
    return checkCloseParen(parsedFile, c, initSize);
  }

  int tempCounter = 0;
  int parsePointer = initSize-1;
  int spaceFound = 0;
  int closeParenFound = 0;

  //printf("DEBUG: checkSpecialToken: initSize=%i\n", initSize);
  while(parsePointer >= 0)
  {
    //printf("DEBUG: checkSpecialToken: checking %c\n", parsedFile[parsePointer]);
    if( parsedFile[parsePointer] == c)
    {
      if(c == '|' || c == '&')
      {
        tempCounter++;
        if(spaceFound || closeParenFound)
        {
          return 0;
        }
        else if(tempCounter > 1)
        {
          return 0;
        }
      }
      else if(c == ';')
      {
        if(closeParenFound)
        {
          return 1;
        }
        else
        {
          return 0;
        }
      }
    }
    else if( parsedFile[parsePointer] == '|' || parsedFile[parsePointer] == '&' || 
             parsedFile[parsePointer] == ';' || parsedFile[parsePointer] == '(' ||
             parsedFile[parsePointer] == '\n')
    {
      return 0;
    }
    else if( isspace(parsedFile[parsePointer]) )
    {
      spaceFound = 1;
    }
    else if( parsedFile[parsePointer] == ')' )
    {
      closeParenFound = 1;
    }
    else if( isValidCharacter(parsedFile[parsePointer]) )
    {
      return 1;
    }
    parsePointer--;
  }


  
  //printf("DEBUG: checkSpecialToken: error 1\n");
  return 0;
}