Refactor parse plain serial #4715

This commit is contained in:
Jerry (Xinyu Hou) 2015-10-23 11:35:28 -07:00
parent 0429986470
commit 978c97cbc0
1 changed files with 41 additions and 47 deletions

View File

@ -118,18 +118,12 @@ void
SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey& key) SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey& key)
{ {
String serial; String serial;
bool parity = false;
String parityStart = plainText.substr(0, 1); String parityStart = plainText.substr(0, 1);
String parityEnd = plainText.substr(plainText.length() - 1, 1); String parityEnd = plainText.substr(plainText.length() - 1, 1);
// check for parity chars { and }, record parity result, then remove them. // check for parity chars { and }, record parity result, then remove them.
if (parityStart == "{" && parityEnd == "}") { if (parityStart == "{" && parityEnd == "}") {
parity = true;
serial = plainText.substr(1, plainText.length() - 2); serial = plainText.substr(1, plainText.length() - 2);
}
else {
serial = plainText;
}
// tokenize serialised subscription. // tokenize serialised subscription.
std::vector<String> parts; std::vector<String> parts;
@ -147,8 +141,7 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey&
} }
// e.g.: {v1;trial;Bob;1;1398297600;1398384000} // e.g.: {v1;trial;Bob;1;1398297600;1398384000}
if (parity if ((parts.size() == 6)
&& (parts.size() == 6)
&& (parts.at(0).find("v1") != String::npos)) { && (parts.at(0).find("v1") != String::npos)) {
key.m_type = parts.at(1); key.m_type = parts.at(1);
key.m_name = parts.at(2); key.m_name = parts.at(2);
@ -176,6 +169,7 @@ SubscriptionManager::parsePlainSerial(const String& plainText, SubscriptionKey&
return; return;
} }
}
throw XSubscription(synergy::string::sprintf("Serial is invalid.")); throw XSubscription(synergy::string::sprintf("Serial is invalid."));
} }