bool CEvaluationNode::operator<(const CEvaluationNode& right) const { if (mainType() != right.mainType()) { return mainType() < right.mainType(); } if (subType() != right.subType()) { return subType() < right.subType(); } switch (mainType()) { case T_CONSTANT: case T_NUMBER: case T_OBJECT: case T_CALL: case T_STRUCTURE: case T_VARIABLE: case T_WHITESPACE: return getData() < right.getData(); break; case T_OPERATOR: case T_FUNCTION: case T_CHOICE: case T_LOGICAL: case T_MV_FUNCTION: case T_VECTOR: case T_DELAY: case T_INVALID: break; } const CEvaluationNode* pChild1 = dynamic_cast<const CEvaluationNode*>(this->getChild()); const CEvaluationNode* pChild2 = dynamic_cast<const CEvaluationNode*>(right.getChild()); while (true) { if (pChild1 == NULL || pChild2 == NULL) { return pChild1 < pChild2; } if (*pChild1 < *pChild2) return true; pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling()); pChild2 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling()); } return false; }
void QMessage::setBody(const QString &body, const QByteArray &mimeType) { QByteArray mainType("text"); QByteArray subType("plain"); QByteArray charset; QString mime = QString(mimeType); int index = mimeType.indexOf("/"); if (index != -1) { mainType = mimeType.left(index).trimmed(); subType = mimeType.mid(index + 1).trimmed(); index = subType.indexOf(";"); if (index != -1) { QString remainder = subType.mid(index + 1); subType = subType.left(index).trimmed(); QRegExp charsetPattern("charset=(\\S+)"); index = charsetPattern.indexIn(remainder); if (index != -1) { charset = charsetPattern.cap(1).toLatin1(); } } } if (charset.isEmpty()) { charset = QMessage::preferredCharsetFor(body); if (charset.isEmpty()) { charset = "UTF-8"; } } QMessageContentContainerPrivate *container(((QMessageContentContainer *)(this))->d_ptr); QMessageContentContainerId existingBodyId(bodyId()); if (existingBodyId.isValid()) { if (existingBodyId == QMessageContentContainerPrivate::bodyContentId()) { // The body content is in the message itself container->setContent(body, mainType, subType, charset); } else { // The body content is in the first attachment QMessageContentContainerPrivate *attachmentContainer(container->attachment(existingBodyId)->d_ptr); attachmentContainer->setContent(body, mainType, subType, charset); } } else { if (container->_attachments.isEmpty()) { // Put the content directly into the message container->setContent(body, mainType, subType, charset); d_ptr->_bodyId = QMessageContentContainerPrivate::bodyContentId(); } else { // Add the body as the first attachment QMessageContentContainer newBody; newBody.d_ptr->setContent(body, mainType, subType, charset); d_ptr->_bodyId = container->prependContent(newBody); } } d_ptr->_modified = true; }
void QMessage::setBody(const QString &bodyText, const QByteArray &mimeType) { QByteArray mainType("text"); QByteArray subType("plain"); QByteArray charset; int index = mimeType.indexOf("/"); if (index != -1) { mainType = mimeType.left(index).trimmed(); subType = mimeType.mid(index + 1).trimmed(); index = subType.indexOf(";"); if (index != -1) { QString remainder = subType.mid(index + 1); subType = subType.left(index).trimmed(); QRegExp charsetPattern("charset=(\\S+)"); index = charsetPattern.indexIn(remainder); if (index != -1) { charset = charsetPattern.cap(1).toLatin1(); } } } if (charset.isEmpty()) { charset = charsetFor(bodyText); } QMailMessageContentType ct; ct.setType(mainType); ct.setSubType(subType); ct.setCharset(charset); QMailMessageBody textBody(QMailMessageBody::fromData(bodyText, ct, QMailMessageBody::Base64)); if (d_ptr->_message.multipartType() == QMailMessage::MultipartNone) { // Replace the body with this data d_ptr->_message.setBody(textBody); } else { // Replace any existing text with this part TextPartLocator locator; d_ptr->_message.foreachPart<TextPartLocator&>(locator); if (locator._location.isValid()) { // Update the existing body text part to contain the new text QMailMessagePart &bodyPart = d_ptr->_message.partAt(locator._location); bodyPart.setBody(textBody); } else { // Insert the text as the new first part QMailMessageContentDisposition cd(QMailMessageContentDisposition::Inline); QMailMessagePart part(QMailMessagePart::fromData(bodyText, ct, cd, QMailMessageBody::Base64)); d_ptr->_message.prependPart(part); } } }