question: int nextNode ( String sStr , int i ) { int nBraces = 0 ; char c = sStr . charAt ( i ) ; do { i ++ ; if ( i < sStr . length ( ) ) { c = sStr . charAt ( i ) ; if ( c == '[' ) { while ( i < sStr . length ( ) && sStr . charAt ( i ) != ']' ) { i ++ ; } i ++ ; if ( i < sStr . length ( ) ) { c = sStr . charAt ( i ) ; } } switch ( c ) { case '(' : nBraces ++ ; break ; case ')' : nBraces -- ; break ; default : break ; } } } while ( i < sStr . length ( ) && ( nBraces > 0 || ( c != ',' && c != ')' && c != '(' ) ) ) ; if ( i >= sStr . length ( ) || nBraces < 0 ) { return - 1 ; } else if ( sStr . charAt ( i ) == ')' ) { i ++ ; if ( sStr . charAt ( i ) == '[' ) { while ( i < sStr . length ( ) && sStr . charAt ( i ) != ']' ) { i ++ ; } i ++ ; if ( i >= sStr . length ( ) ) { return - 1 ; } } if ( sStr . charAt ( i ) == ':' ) { i ++ ; c = sStr . charAt ( i ) ; while ( i < sStr . length ( ) && ( c == '.' || Character . isDigit ( c ) ) ) { i ++ ; if ( i < sStr . length ( ) ) { c = sStr . charAt ( i ) ; } } } } return i ; }
target:  helper method for parsing Newick tree 