Added helper function to replace header field.
This commit is contained in:
parent
281300ed6a
commit
d8b3d2b641
@ -276,6 +276,13 @@ void header::removeField(const size_t pos)
|
||||
}
|
||||
|
||||
|
||||
void header::replaceField(ref <headerField> field, ref <headerField> newField)
|
||||
{
|
||||
insertFieldBefore(field, newField);
|
||||
removeField(field);
|
||||
}
|
||||
|
||||
|
||||
void header::removeAllFields()
|
||||
{
|
||||
m_fields.clear();
|
||||
|
@ -43,6 +43,8 @@ VMIME_TEST_SUITE_BEGIN
|
||||
VMIME_TEST(testInsertFieldAfter1)
|
||||
VMIME_TEST(testInsertFieldAfter2)
|
||||
|
||||
VMIME_TEST(testReplaceField)
|
||||
|
||||
VMIME_TEST(testRemoveField1)
|
||||
VMIME_TEST(testRemoveField2)
|
||||
|
||||
@ -192,6 +194,23 @@ VMIME_TEST_SUITE_BEGIN
|
||||
VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
|
||||
}
|
||||
|
||||
// replaceField
|
||||
void testReplaceField()
|
||||
{
|
||||
vmime::header hdr;
|
||||
hdr.parse("A: a\r\nB: b\r\nC: c\r\n");
|
||||
|
||||
vmime::ref <vmime::headerField> hf = vmime::headerFieldFactory::getInstance()->create("Z", "z");
|
||||
hdr.replaceField(hdr.getField("B"), hf);
|
||||
|
||||
std::vector <vmime::ref <vmime::headerField> > res = hdr.getFieldList();
|
||||
|
||||
VASSERT_EQ("Count", static_cast <unsigned int>(3), res.size());
|
||||
VASSERT_EQ("First value", "A: a", headerTest::getFieldValue(*res[0]));
|
||||
VASSERT_EQ("Second value", "Z: z", headerTest::getFieldValue(*res[1]));
|
||||
VASSERT_EQ("Third value", "C: c", headerTest::getFieldValue(*res[2]));
|
||||
}
|
||||
|
||||
// removeField
|
||||
void testRemoveField1()
|
||||
{
|
||||
|
@ -170,6 +170,14 @@ public:
|
||||
*/
|
||||
void removeField(const size_t pos);
|
||||
|
||||
/** Replaces a field with another field.
|
||||
*
|
||||
* @param field field to be replaced
|
||||
* @param newField field to replace with
|
||||
* @throw exceptions::no_such_field if the field is not in the list
|
||||
*/
|
||||
void replaceField(ref <headerField> field, ref <headerField> newField);
|
||||
|
||||
/** Remove all fields from the list.
|
||||
*/
|
||||
void removeAllFields();
|
||||
|
Loading…
Reference in New Issue
Block a user