X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fprops%2Fprops.cxx;h=3d63758e143707fe38b100728e8ac6f7534f2e99;hb=284a9e061280535de01b0e3f36a9b85ef8178e61;hp=c662eb7f95f808ab54af4f33b4453c08c015063e;hpb=11479cd8c386d8bf7e1fee7bed60ab4abefc5fad;p=simgear.git diff --git a/simgear/props/props.cxx b/simgear/props/props.cxx index c662eb7f..3d63758e 100644 --- a/simgear/props/props.cxx +++ b/simgear/props/props.cxx @@ -94,7 +94,7 @@ public: template inline Range -parse_name (const Range &path) +parse_name (const SGPropertyNode *node, const Range &path) { typename Range::iterator i = path.begin(); typename Range::iterator max = path.end(); @@ -118,15 +118,24 @@ parse_name (const Range &path) } else if (*i == '[' || *i == '/') { break; } else { - throw string("name may contain only ._- and alphanumeric characters"); + string err = "'"; + err.push_back(*i); + err.append("' found in propertyname after '"+node->getNameString()+"'"); + err.append("\nname may contain only ._- and alphanumeric characters"); + throw err; } i++; } } else { - if (path.begin() == i) - throw string("name must begin with alpha or '_'"); + if (path.begin() == i) { + string err = "'"; + err.push_back(*i); + err.append("' found in propertyname after '"+node->getNameString()+"'"); + err.append("\nname must begin with alpha or '_'"); + throw err; + } } return Range(path.begin(), i); } @@ -268,7 +277,7 @@ find_node_aux(SGPropertyNode * current, SplitItr& itr, bool create, // Empty name at this point is empty, not root. if (token.empty()) return find_node_aux(current, ++itr, create, last_index); - Range name = parse_name(token); + Range name = parse_name(current, token); if (equals(name, ".")) return find_node_aux(current, ++itr, create, last_index); if (equals(name, "..")) { @@ -1027,17 +1036,22 @@ SGPropertyNode::getDisplayName (bool simplify) const } -const char * +string SGPropertyNode::getPath (bool simplify) const { - // Calculate the complete path only once. - if (_parent != 0 && _path.empty()) { - _path = _parent->getPath(simplify); - _path += '/'; - _path += getDisplayName(simplify); + typedef std::vector PList; + PList pathList; + for (const SGPropertyNode* node = this; node->_parent; node = node->_parent) + pathList.push_back(node); + string result; + for (PList::reverse_iterator itr = pathList.rbegin(), + rend = pathList.rend(); + itr != rend; + ++itr) { + result += '/'; + result += (*itr)->getDisplayName(simplify); } - - return _path.c_str(); + return result; } props::Type