Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions | Static Protected Member Functions
nsAbQueryStringToExpression Class Reference

#include <nsAbQueryStringToExpression.h>

List of all members.

Static Public Member Functions

static nsresult Convert (const char *queryString, nsIAbBooleanExpression **expression)

Static Protected Member Functions

static nsresult ParseExpression (const char **index, nsISupports **expression)
static nsresult ParseExpressions (const char **index, nsIAbBooleanExpression *expression)
static nsresult ParseCondition (const char **index, const char *indexBracketClose, nsIAbBooleanConditionString **conditionString)
static nsresult ParseConditionEntry (const char **index, const char *indexBracketClose, char **entry)
static nsresult ParseOperationEntry (const char *indexBracketOpen1, const char *indexBracketOpen2, char **operation)
static nsresult CreateBooleanExpression (const char *operation, nsIAbBooleanExpression **expression)
static nsresult CreateBooleanConditionString (const char *attribute, const char *condition, const char *value, nsIAbBooleanConditionString **conditionString)

Detailed Description

Definition at line 44 of file nsAbQueryStringToExpression.h.


Member Function Documentation

nsresult nsAbQueryStringToExpression::Convert ( const char *  queryString,
nsIAbBooleanExpression **  expression 
) [static]

Definition at line 52 of file nsAbQueryStringToExpression.cpp.

{
    nsresult rv;

    nsCAutoString q(queryString);
    q.StripWhitespace ();
    queryString = q.get ();

    nsCOMPtr<nsISupports> s;
    rv = ParseExpression (&queryString, getter_AddRefs(s));
    NS_ENSURE_SUCCESS(rv, rv);

    // Case: Not end of string
    if (*queryString != 0)
        return NS_ERROR_FAILURE;

    nsCOMPtr<nsIAbBooleanExpression> e(do_QueryInterface(s, &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    NS_IF_ADDREF(*expression = e);
    return rv;
}

Here is the call graph for this function:

nsresult nsAbQueryStringToExpression::CreateBooleanConditionString ( const char *  attribute,
const char *  condition,
const char *  value,
nsIAbBooleanConditionString **  conditionString 
) [static, protected]

Definition at line 278 of file nsAbQueryStringToExpression.cpp.

{
    if (attribute == 0 || condition == 0 || value == 0)
        return NS_ERROR_FAILURE;

    nsAbBooleanConditionType c;

    if (nsCRT::strcasecmp (condition, "=") == 0)
        c = nsIAbBooleanConditionTypes::Is;
    else if (nsCRT::strcasecmp (condition, "!=") == 0)
        c = nsIAbBooleanConditionTypes::IsNot;
    else if (nsCRT::strcasecmp (condition, "lt") == 0)
        c = nsIAbBooleanConditionTypes::LessThan;
    else if (nsCRT::strcasecmp (condition, "gt") == 0)
        c = nsIAbBooleanConditionTypes::GreaterThan;
    else if (nsCRT::strcasecmp (condition, "bw") == 0)
        c = nsIAbBooleanConditionTypes::BeginsWith;
    else if (nsCRT::strcasecmp (condition, "ew") == 0)
        c = nsIAbBooleanConditionTypes::EndsWith;
    else if (nsCRT::strcasecmp (condition, "c")== 0)
        c = nsIAbBooleanConditionTypes::Contains;
    else if (nsCRT::strcasecmp (condition, "!c") == 0)
        c = nsIAbBooleanConditionTypes::DoesNotContain;
    else if (nsCRT::strcasecmp (condition, "~=") == 0)
        c = nsIAbBooleanConditionTypes::SoundsLike;
    else if (nsCRT::strcasecmp (condition, "regex") == 0)
        c = nsIAbBooleanConditionTypes::RegExp;
    else
        return NS_ERROR_FAILURE;

    nsresult rv;

    nsCOMPtr<nsIAbBooleanConditionString> cs = do_CreateInstance(NS_BOOLEANCONDITIONSTRING_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = cs->SetCondition (c);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID,&rv); 
    if (NS_SUCCEEDED(rv))
    {
        nsXPIDLString attributeUCS2;
        nsXPIDLString valueUCS2;

        rv = textToSubURI->UnEscapeAndConvert("UTF-8",
            attribute, getter_Copies(attributeUCS2));
        NS_ENSURE_SUCCESS(rv, rv);

        rv = textToSubURI->UnEscapeAndConvert("UTF-8",
            value, getter_Copies(valueUCS2));
        NS_ENSURE_SUCCESS(rv, rv);

        NS_ConvertUCS2toUTF8 attributeUTF8(attributeUCS2);

        rv = cs->SetName (attributeUTF8.get ());
        NS_ENSURE_SUCCESS(rv, rv);
        rv = cs->SetValue (valueUCS2);
        NS_ENSURE_SUCCESS(rv, rv);
    }
    else
    {
        NS_ConvertUTF8toUCS2 valueUCS2(value);

        rv = cs->SetName (attribute);
        NS_ENSURE_SUCCESS(rv, rv);
        rv = cs->SetValue (valueUCS2.get ());
        NS_ENSURE_SUCCESS(rv, rv);
    }
            

    NS_IF_ADDREF(*conditionString = cs);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbQueryStringToExpression::CreateBooleanExpression ( const char *  operation,
nsIAbBooleanExpression **  expression 
) [static, protected]

Definition at line 253 of file nsAbQueryStringToExpression.cpp.

{
    nsAbBooleanOperationType op;
    if (nsCRT::strcasecmp (operation, "and") == 0)
        op = nsIAbBooleanOperationTypes::AND;
    else if (nsCRT::strcasecmp (operation, "or") == 0)
        op = nsIAbBooleanOperationTypes::OR;
    else if (nsCRT::strcasecmp (operation, "not") == 0)
        op = nsIAbBooleanOperationTypes::NOT;
    else
        return NS_ERROR_FAILURE;

    nsresult rv;

    nsCOMPtr <nsIAbBooleanExpression> expr = do_CreateInstance(NS_BOOLEANEXPRESSION_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    NS_IF_ADDREF(*expression = expr);
    
    rv = expr->SetOperation (op);
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbQueryStringToExpression::ParseCondition ( const char **  index,
const char *  indexBracketClose,
nsIAbBooleanConditionString **  conditionString 
) [static, protected]

Definition at line 179 of file nsAbQueryStringToExpression.cpp.

{
    nsresult rv;

    (*index)++;

    nsXPIDLCString entries[3];
    for (int i = 0; i < 3; i++)
    {
        rv = ParseConditionEntry (index, indexBracketClose,
                getter_Copies (entries[i]));
        NS_ENSURE_SUCCESS(rv, rv);

        if (*index == indexBracketClose)
            break;
    }
    
    if (*index != indexBracketClose)
        return NS_ERROR_FAILURE;

    nsCOMPtr<nsIAbBooleanConditionString> c;
    rv = CreateBooleanConditionString (
        entries[0],
        entries[1],
        entries[2],
        getter_AddRefs (c));
    NS_ENSURE_SUCCESS(rv, rv);

    NS_IF_ADDREF(*conditionString = c);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbQueryStringToExpression::ParseConditionEntry ( const char **  index,
const char *  indexBracketClose,
char **  entry 
) [static, protected]

Definition at line 214 of file nsAbQueryStringToExpression.cpp.

{
    const char* indexDeliminator = *index;
    while (indexDeliminator != indexBracketClose &&
        *indexDeliminator != ',')
        indexDeliminator++;

    int entryLength = indexDeliminator - *index;
    if (entryLength)
        *entry = nsCRT::strndup (*index, entryLength); 
    else
        *entry = 0;

    if (indexDeliminator != indexBracketClose)
        *index = indexDeliminator + 1;
    else
        *index = indexDeliminator;

    return NS_OK;
}

Here is the caller graph for this function:

nsresult nsAbQueryStringToExpression::ParseExpression ( const char **  index,
nsISupports **  expression 
) [static, protected]

Definition at line 77 of file nsAbQueryStringToExpression.cpp.

{
    nsresult rv;

    if (**index != '(')
        return NS_ERROR_FAILURE;

    const char* indexBracket = *index + 1;
    while (*indexBracket &&
        *indexBracket != '(' && *indexBracket != ')')
        indexBracket++;

    // Case: End of string
    if (*indexBracket == 0)
        return NS_ERROR_FAILURE;

    // Case: "((" or "()"
    if (indexBracket == *index + 1)
    {
         return NS_ERROR_FAILURE;
    }
    // Case: "(*("
    else if (*indexBracket == '(')
    {
        // printf ("Case: (*(: %s\n", *index);

        nsXPIDLCString operation;
        rv = ParseOperationEntry (
            *index, indexBracket,
            getter_Copies (operation));
        NS_ENSURE_SUCCESS(rv, rv);

        nsCOMPtr<nsIAbBooleanExpression> e;
        rv = CreateBooleanExpression(operation,
            getter_AddRefs(e));
        NS_ENSURE_SUCCESS(rv, rv);

        // Case: "(*)(*)....(*))"
        *index = indexBracket;
        rv = ParseExpressions (index, e);
        NS_ENSURE_SUCCESS(rv, rv);

        NS_IF_ADDREF(*expression = e);
    }
    // Case" "(*)"
    else if (*indexBracket == ')')
    {
        // printf ("Case: (*): %s\n", *index);

        nsCOMPtr<nsIAbBooleanConditionString> conditionString;
        rv = ParseCondition (index, indexBracket,
            getter_AddRefs(conditionString));
        NS_ENSURE_SUCCESS(rv, rv);

        NS_IF_ADDREF(*expression = conditionString);
    }

    if (**index != ')')
        return NS_ERROR_FAILURE;

    (*index)++;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbQueryStringToExpression::ParseExpressions ( const char **  index,
nsIAbBooleanExpression expression 
) [static, protected]

Definition at line 145 of file nsAbQueryStringToExpression.cpp.

{
    nsresult rv;

    nsCOMPtr<nsISupportsArray> expressions;
    NS_NewISupportsArray(getter_AddRefs(expressions));

    // Case: ")(*)(*)....(*))"
    // printf ("Case: )(*)(*)....(*)): %s\n", *index);
    while (**index == '(')
    {
        nsCOMPtr<nsISupports> childExpression;
        rv = ParseExpression (index, getter_AddRefs (childExpression));
        NS_ENSURE_SUCCESS(rv, rv);

        expressions->AppendElement (childExpression);
    }

    if (**index == 0)
        return NS_ERROR_FAILURE;

    // Case: "))"
    // printf ("Case: )): %s\n", *index);

    if (**index != ')')
        return NS_ERROR_FAILURE;

    expression->SetExpressions (expressions);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAbQueryStringToExpression::ParseOperationEntry ( const char *  indexBracketOpen1,
const char *  indexBracketOpen2,
char **  operation 
) [static, protected]

Definition at line 238 of file nsAbQueryStringToExpression.cpp.

{
    int operationLength = indexBracketOpen2 - indexBracketOpen1 - 1;
    if (operationLength)
        *operation = nsCRT::strndup (indexBracketOpen1 + 1,
            operationLength); 
    else
        *operation = 0;

    return NS_OK;
}

Here is the caller graph for this function:


The documentation for this class was generated from the following files: