Exemple #1
0
/*
 * Returns the VCard - iCal string fro this VObject.
 * Note:
 * The returned WCHAR* is new allocated, must be freed by the caller.
 */
WCHAR* VObject::toString() {

    WString strVObject;

    bool is_30 = false;
    if (version) {
        is_30 = !wcscmp(getVersion(), TEXT("3.0"));
    }

    // *** FIXME ***
    // By now folding feature not supported on server...
    bool useFolding = false;

    // let's reserve some space to avoid reallocation in most cases
    strVObject.reserve(5000);

    for (int i=0; i<properties->size(); i++) {
        VProperty *prop = getProperty(i);
        WCHAR* propString = prop->toString(version);
        WCHAR* valueConv = NULL;

        // Folding
        if (useFolding && wcslen(propString) > VCARD_MAX_LINE_LEN) {
            valueConv = folding(propString, VCARD_MAX_LINE_LEN);
            strVObject.append(valueConv);
        }
        else {
            strVObject.append(propString);
        }
        strVObject.append(RFC822_LINE_BREAK);

        if (propString) {
            delete [] propString;  propString = NULL;
        }
        if (valueConv) {
            delete [] valueConv;   valueConv = NULL;
        }
    }

    // memory must be free by caller with delete []
    WCHAR *str = wstrdup(strVObject);
    return str;
}