diff options
author | Vincent Richard <[email protected]> | 2004-10-21 15:05:47 +0000 |
---|---|---|
committer | Vincent Richard <[email protected]> | 2004-10-21 15:05:47 +0000 |
commit | 2949fb51f13e1236d5c161f02e1c2c8541100e9f (patch) | |
tree | 991edcf50483116ce83977a4d9e652de8c5328dc /src/parameter.cpp | |
parent | header class unit tests added (diff) | |
download | vmime-2949fb51f13e1236d5c161f02e1c2c8541100e9f.tar.gz vmime-2949fb51f13e1236d5c161f02e1c2c8541100e9f.zip |
Refactoring (see ChangeLog).
Diffstat (limited to 'src/parameter.cpp')
-rw-r--r-- | src/parameter.cpp | 109 |
1 files changed, 108 insertions, 1 deletions
diff --git a/src/parameter.cpp b/src/parameter.cpp index 98111cb0..7c673703 100644 --- a/src/parameter.cpp +++ b/src/parameter.cpp @@ -34,9 +34,116 @@ parameter* parameter::clone() const } -void parameter::copyFrom(const parameter& param) +void parameter::copyFrom(const component& other) { + const parameter& param = dynamic_cast <const parameter&>(other); + m_name = param.m_name; + + getValue().copyFrom(param.getValue()); +} + + +parameter& parameter::operator=(const parameter& other) +{ + copyFrom(other); + return (*this); +} + + +const string& parameter::getName() const +{ + return (m_name); +} + + +void parameter::parse(const string& buffer, const string::size_type position, + const string::size_type end, string::size_type* newPosition) +{ + getValue().parse(buffer, position, end, newPosition); +} + + +void parameter::generate(utility::outputStream& os, const string::size_type maxLineLength, + const string::size_type curLinePos, string::size_type* newLinePos) const +{ + string::size_type pos = curLinePos; + + if (pos + m_name.length() + 10 > maxLineLength) + { + os << NEW_LINE_SEQUENCE; + pos = NEW_LINE_SEQUENCE_LENGTH; + } + + os << m_name << "="; + pos += m_name.length() + 1; + + generateValue(os, maxLineLength, pos, newLinePos); +} + + +void parameter::generateValue(utility::outputStream& os, const string::size_type /* maxLineLength */, + const string::size_type curLinePos, string::size_type* newLinePos) const +{ + std::ostringstream valueStream; + utility::outputStreamAdapter valueStreamV(valueStream); + + // TODO: can we imagine having values that span on multiple lines? + getValue().generate(valueStreamV, lineLengthLimits::infinite, 0, NULL); + + const string value(valueStream.str()); + + std::ostringstream ss; + string::const_iterator start = value.begin(); + bool quoted = false; + + for (string::const_iterator i = value.begin() ; i != value.end() ; ++i) + { + switch (*i) + { + // Characters that need to be quoted _and_ escaped + case '"': + case '\\': + + ss << string(start, i) << "\\" << *i; + + start = i + 1; + quoted = true; + + break; + + // Other characters that need quoting + case ' ': + case '\t': + case '(': + case ')': + case '<': + case '>': + case '@': + case ',': + case ';': + case ':': + case '/': + case '[': + case ']': + case '?': + case '=': + + quoted = true; + break; + } + } + + if (start != value.end()) + ss << string(start, value.end()); + + if (quoted) + os << "\"" << ss.str() << "\""; + else + os << ss.str(); + + if (newLinePos) + *newLinePos = curLinePos + ss.str().length() + 2; } |