summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/messaging/Address.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/qpid/messaging/Address.cpp')
-rw-r--r--cpp/src/qpid/messaging/Address.cpp203
1 files changed, 0 insertions, 203 deletions
diff --git a/cpp/src/qpid/messaging/Address.cpp b/cpp/src/qpid/messaging/Address.cpp
index ff72f62705..057196a957 100644
--- a/cpp/src/qpid/messaging/Address.cpp
+++ b/cpp/src/qpid/messaging/Address.cpp
@@ -156,207 +156,4 @@ InvalidAddress::InvalidAddress(const std::string& msg) : Exception(msg) {}
MalformedAddress::MalformedAddress(const std::string& msg) : Exception(msg) {}
-AddressParser::AddressParser(const std::string& s) : input(s), current(0) {}
-
-bool AddressParser::error(const std::string& message)
-{
- throw MalformedAddress((boost::format("%1%, character %2% of %3%") % message % current % input).str());
-}
-
-bool AddressParser::parse(Address& address)
-{
- std::string name;
- if (readName(name)) {
- if (name.find('#') == 0) name = qpid::framing::Uuid(true).str() + name;
- address.setName(name);
- if (readChar('/')) {
- std::string subject;
- if (readSubject(subject)) {
- address.setSubject(subject);
- } else {
- return error("Expected subject after /");
- }
- }
- if (readChar(';')) {
- Variant options = Variant::Map();
- if (readMap(options)) {
- address.setOptions(options.asMap());
- }
- }
- //skip trailing whitespace
- while (!eos() && iswhitespace()) ++current;
- return eos() || error("Unexpected chars in address: " + input.substr(current));
- } else {
- return input.empty() || error("Expected name");
- }
-}
-
-bool AddressParser::readList(Variant& value)
-{
- if (readChar('[')) {
- value = Variant::List();
- Variant item;
- while (readValue(item)) {
- value.asList().push_back(item);
- if (!readChar(',')) break;
- }
- return readChar(']') || error("Unmatched '['!");
- } else {
- return false;
- }
-}
-
-bool AddressParser::readMap(Variant& value)
-{
- if (readChar('{')) {
- value = Variant::Map();
- while (readKeyValuePair(value.asMap()) && readChar(',')) {}
- return readChar('}') || error("Unmatched '{'!");
- } else {
- return false;
- }
-}
-
-bool AddressParser::readKeyValuePair(Variant::Map& map)
-{
- std::string key;
- Variant value;
- if (readKey(key)) {
- if (readChar(':') && readValue(value)) {
- map[key] = value;
- return true;
- } else {
- return error("Bad key-value pair, expected ':'");
- }
- } else {
- return false;
- }
-}
-
-bool AddressParser::readKey(std::string& key)
-{
- return readWord(key);
-}
-
-bool AddressParser::readValue(Variant& value)
-{
- return readSimpleValue(value) || readQuotedValue(value) ||
- readMap(value) || readList(value) || error("Expected value");
-}
-
-bool AddressParser::readString(std::string& value, char delimiter)
-{
- if (readChar(delimiter)) {
- std::string::size_type start = current++;
- while (!eos()) {
- if (input.at(current) == delimiter) {
- if (current > start) {
- value = input.substr(start, current - start);
- } else {
- value = "";
- }
- ++current;
- return true;
- } else {
- ++current;
- }
- }
- return error("Unmatched delimiter");
- } else {
- return false;
- }
-}
-
-bool AddressParser::readName(std::string& name)
-{
- return readQuotedString(name) || readWord(name, "/;");
-}
-
-bool AddressParser::readSubject(std::string& subject)
-{
- return readQuotedString(subject) || readWord(subject, ";");
-}
-
-bool AddressParser::readQuotedString(std::string& s)
-{
- return readString(s, '"') || readString(s, '\'');
-}
-
-bool AddressParser::readQuotedValue(Variant& value)
-{
- std::string s;
- if (readQuotedString(s)) {
- value = s;
- return true;
- } else {
- return false;
- }
-}
-
-bool AddressParser::readSimpleValue(Variant& value)
-{
- std::string s;
- if (readWord(s)) {
- value = s;
- try { value = value.asInt64(); return true; } catch (const InvalidConversion&) {}
- try { value = value.asDouble(); return true; } catch (const InvalidConversion&) {}
- return true;
- } else {
- return false;
- }
-}
-
-bool AddressParser::readWord(std::string& value, const std::string& delims)
-{
- //skip leading whitespace
- while (!eos() && iswhitespace()) ++current;
-
- //read any number of non-whitespace, non-reserved chars into value
- std::string::size_type start = current;
- while (!eos() && !iswhitespace() && !in(delims)) ++current;
-
- if (current > start) {
- value = input.substr(start, current - start);
- return true;
- } else {
- return false;
- }
-}
-
-bool AddressParser::readChar(char c)
-{
- while (!eos()) {
- if (iswhitespace()) {
- ++current;
- } else if (input.at(current) == c) {
- ++current;
- return true;
- } else {
- return false;
- }
- }
- return false;
-}
-
-bool AddressParser::iswhitespace()
-{
- return ::isspace(input.at(current));
-}
-
-bool AddressParser::isreserved()
-{
- return in(RESERVED);
-}
-
-bool AddressParser::in(const std::string& chars)
-{
- return chars.find(input.at(current)) != std::string::npos;
-}
-
-bool AddressParser::eos()
-{
- return current >= input.size();
-}
-
-const std::string AddressParser::RESERVED = "\'\"{}[],:/";
}} // namespace qpid::messaging