MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/OpenColorIO / FindEndOfName

Function FindEndOfName

src/OpenColorIO/ParseUtils.cpp:702–747  ·  view source on GitHub ↗

Find the end of a name from a list contained in a string. The elements of the list are separated by the character defined by the sep argument. A name can be surrounded by quotes to enable names including the sep symbol, in other words, to prevent it from being used as a separator.

Source from the content-addressed store, hash-verified

700// A name can be surrounded by quotes to enable names including the sep symbol, in
701// other words, to prevent it from being used as a separator.
702static int FindEndOfName(const std::string & s, size_t start, char sep)
703{
704 int currentPos = static_cast<int>(start);
705 int nameEndPos = currentPos;
706 bool isEndFound = false;
707
708 std::string symbols = "\"";
709 symbols += sep;
710
711 while ( !isEndFound )
712 {
713 nameEndPos = static_cast<int>( s.find_first_of( symbols, currentPos ) );
714 if ( nameEndPos == static_cast<int>(std::string::npos) )
715 {
716 // Reached the end of the list.
717 nameEndPos = static_cast<int>( s.size() );
718 isEndFound = true;
719 }
720 else if ( s[nameEndPos] == '"' )
721 {
722 // Found a quote, need to find the next one.
723 nameEndPos = static_cast<int>( s.find_first_of("\"", nameEndPos + 1) );
724 if ( nameEndPos == (int)std::string::npos )
725 {
726 // Reached the end of the list instead.
727 std::ostringstream os;
728 os << "The string '" << s << "' is not correctly formatted. " <<
729 "It is missing a closing quote.";
730 throw Exception(os.str().c_str());
731 }
732 else
733 {
734 // Found the second quote, need to continue the search for a symbol
735 // separating the elements (: or ,).
736 currentPos = nameEndPos + 1;
737 }
738 }
739 else if( s[nameEndPos] == sep )
740 {
741 // Found a symbol separating the elements, stop here.
742 isEndFound = true;
743 }
744 }
745
746 return nameEndPos;
747}
748
749StringUtils::StringVec SplitStringEnvStyle(const std::string & str)
750{

Callers 1

SplitStringEnvStyleFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected