@@ -346,36 +346,38 @@ StringView TreeNode::getRawPortValue(const std::string& key) const
346346 return remap_it->second ;
347347}
348348
349- bool TreeNode::isBlackboardPointer (StringView str)
349+ bool TreeNode::isBlackboardPointer (StringView str, StringView* stripped_pointer )
350350{
351- const auto size = str.size ();
352- if (size >= 3 && str.back () == ' }' )
351+ if (str.size () < 3 )
353352 {
354- if (str[0 ] == ' {' )
355- {
356- return true ;
357- }
358- if (size >= 4 && str[0 ] == ' $' && str[1 ] == ' {' )
359- {
360- return true ;
361- }
353+ return false ;
354+ }
355+ // strip leading and following spaces
356+ size_t front_index = 0 ;
357+ size_t last_index = str.size ()-1 ;
358+ while (str[front_index] == ' ' && front_index <= last_index)
359+ {
360+ front_index++;
361+ }
362+ while (str[last_index] == ' ' && front_index <= last_index)
363+ {
364+ last_index--;
365+ }
366+ const auto size = (last_index-front_index) + 1 ;
367+ auto valid = size >= 3 && str[front_index] == ' {' && str[last_index] == ' }' ;
368+ if (valid && stripped_pointer)
369+ {
370+ *stripped_pointer = StringView ( &str[front_index+1 ], size-2 );
362371 }
363- return false ;
372+ return valid ;
364373}
365374
366375StringView TreeNode::stripBlackboardPointer (StringView str)
367376{
368- const auto size = str. size () ;
369- if (size >= 3 && str. back () == ' } ' )
377+ StringView out ;
378+ if ( isBlackboardPointer (str, &out) )
370379 {
371- if (str[0 ] == ' {' )
372- {
373- return str.substr (1 , size - 2 );
374- }
375- if (str[0 ] == ' $' && str[1 ] == ' {' )
376- {
377- return str.substr (2 , size - 3 );
378- }
380+ return out;
379381 }
380382 return {};
381383}
@@ -387,9 +389,10 @@ Expected<StringView> TreeNode::getRemappedKey(StringView port_name,
387389 {
388390 return {port_name};
389391 }
390- if (isBlackboardPointer (remapped_port))
392+ StringView stripped;
393+ if (isBlackboardPointer (remapped_port, &stripped))
391394 {
392- return {stripBlackboardPointer (remapped_port) };
395+ return {stripped };
393396 }
394397 return nonstd::make_unexpected (" Not a blackboard pointer" );
395398}
0 commit comments