| 480 | } |
| 481 | |
| 482 | string JsonTree::getPath( char separator ) const |
| 483 | { |
| 484 | string result; |
| 485 | |
| 486 | const JsonTree *node = this; |
| 487 | bool prevWasArrayIndex = false; |
| 488 | while( node != 0 ) { |
| 489 | bool isArrayIndex = false; |
| 490 | string nodeName = node->mKey; |
| 491 | if( nodeName.empty() && node->mParent ) { // should be an array index; find out which by searching our parent's children for ourselves |
| 492 | size_t index = 0; |
| 493 | for( ConstIter parentChildIt = node->mParent->mChildren.begin(); parentChildIt != node->mParent->mChildren.end(); ++parentChildIt, ++index ) { |
| 494 | if( &(*parentChildIt) == node ) { |
| 495 | isArrayIndex = true; |
| 496 | break; |
| 497 | } |
| 498 | } |
| 499 | if( isArrayIndex ) { |
| 500 | nodeName = '[' + toString( index ) + ']'; |
| 501 | } |
| 502 | } |
| 503 | if( (! prevWasArrayIndex) && (! nodeName.empty()) && ( node != this ) ) { |
| 504 | result = nodeName + separator + result; |
| 505 | } else if( ! nodeName.empty() ) { |
| 506 | result = nodeName + result; |
| 507 | } |
| 508 | node = node->mParent; |
| 509 | prevWasArrayIndex = isArrayIndex; |
| 510 | } |
| 511 | return result; |
| 512 | } |
| 513 | |
| 514 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 515 |
no test coverage detected