- Path path;
- // Skip the initial attribute name if given
- std::string::size_type i = s.find_first_of("[.");
- std::string attribute = s.substr(0, i);
- while (i < s.size()) {
- if (s[i] == '[') {
- ++i;
- unsigned index = 0;
- while (i < s.size()) {
- if (s[i] == ']')
- break;
- unsigned v = s[i] - '0';
- // Error, no number
- if (10 <= v) {
- SG_LOG(SG_NETWORK, SG_WARN, "HLADataElement: invalid character in array subscript for \""
- << s << "\" at \"" << attribute << toString(path) << "\"!");
- return AttributePathPair();
- }
- index *= 10;
- index += v;
- ++i;
- }
- path.push_back(index);
- ++i;
- continue;
- }
- if (s[i] == '.') {
- // Error, . cannot be last
- if (s.size() <= ++i) {
- SG_LOG(SG_NETWORK, SG_WARN, "HLADataElement: invalid terminating '.' for \""
- << s << "\"!");
- return AttributePathPair();
- }
- std::string::size_type e = s.find_first_of("[.", i);
- path.push_back(s.substr(i, e - i));
- i = e;
- continue;
- }
- }
-
- return AttributePathPair(attribute, path);