added SymbolString(SymbolString), optimized

This commit is contained in:
john30
2014-12-03 23:02:30 +01:00
parent 508eedbe51
commit 09b2d969be
2 changed files with 20 additions and 4 deletions
+13 -2
View File
@@ -48,7 +48,7 @@ static const unsigned char CRC_LOOKUP_TABLE[] =
}; };
SymbolString::SymbolString(const string str) SymbolString::SymbolString(const string& str)
: m_unescapeState(0), m_crc(0) : m_unescapeState(0), m_crc(0)
{ {
// parse + escape // parse + escape
@@ -60,7 +60,18 @@ SymbolString::SymbolString(const string str)
push_back(m_crc, false, false); push_back(m_crc, false, false);
} }
SymbolString::SymbolString(const string str, bool isEscaped) SymbolString::SymbolString(const SymbolString& str)
: m_unescapeState(0), m_crc(0)
{
// escape
for (size_t i = 0; i < str.size(); i++) {
push_back(str[i], false, true);
}
// add CRC + escape
push_back(m_crc, false, false);
}
SymbolString::SymbolString(const string& str, bool isEscaped)
: m_unescapeState(1), m_crc(0) : m_unescapeState(1), m_crc(0)
{ {
// parse + optionally unescape // parse + optionally unescape
+7 -2
View File
@@ -50,13 +50,18 @@ public:
* @brief Creates a new escaped instance from an unescaped hex string and adds the calculated CRC. * @brief Creates a new escaped instance from an unescaped hex string and adds the calculated CRC.
* @param str the unescaped hex string. * @param str the unescaped hex string.
*/ */
SymbolString(const string str); SymbolString(const string& str);
/**
* @brief Creates a new escaped instance from an unescaped @a SymbolString and adds the calculated CRC.
* @param str the unescaped SymbolString.
*/
SymbolString(const SymbolString& str);
/** /**
* @brief Creates a new unescaped instance from a hex string. * @brief Creates a new unescaped instance from a hex string.
* @param isEscaped whether the hex string is escaped and shall be unescaped. * @param isEscaped whether the hex string is escaped and shall be unescaped.
* @param str the hex string. * @param str the hex string.
*/ */
SymbolString(const string str, const bool isEscaped); SymbolString(const string& str, const bool isEscaped);
/** /**
* @brief Returns the symbols as hex string. * @brief Returns the symbols as hex string.
* @param unescape whether to unescape an escaped instance. * @param unescape whether to unescape an escaped instance.