Skip to content

Commit

Permalink
Fix for LookParser, getNum returning 1 on empty string and added conf…
Browse files Browse the repository at this point in the history
…ig tests
  • Loading branch information
larochj committed Dec 13, 2024
1 parent 8b0a0b9 commit 6df1d60
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,13 @@ const char * Config::getActiveDisplay( int index ) const

int Config::getNumActiveDisplays() const
{
const int numActiveDisplays = static_cast<int>(getImpl()->m_activeDisplays.size());
if( numActiveDisplays == 1 &&
getImpl()->m_activeDisplays[0].empty() )
{
return 0;
}

return static_cast<int>(getImpl()->m_activeDisplays.size());
}

Expand Down Expand Up @@ -4179,6 +4186,13 @@ const char * Config::getActiveView( int index ) const

int Config::getNumActiveViews() const
{
const int numActiveViews = static_cast<int>(getImpl()->m_activeViews.size());
if( numActiveViews == 1 &&
getImpl()->m_activeViews[0].empty() )
{
return 0;
}

return static_cast<int>(getImpl()->m_activeViews.size());
}

Expand Down
6 changes: 0 additions & 6 deletions src/OpenColorIO/LookParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ const LookParseResult::Options & LookParseResult::parse(const std::string & look
tokens.push_back(t);
}

if( vec.size() == 0 )
{
LookParseResult::Token t;
tokens.push_back(t);
}

m_options.push_back(tokens);
}

Expand Down
1 change: 0 additions & 1 deletion src/OpenColorIO/OCIOYaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5002,7 +5002,6 @@ inline void save(YAML::Emitter & out, const Config & config)
// The YAML library will wrap names that use a comma in quotes.
out << YAML::Value << YAML::Flow << active_displays;


out << YAML::Key << "active_views";
StringUtils::StringVec active_views;
int nViews = config.getNumActiveViews();
Expand Down
2 changes: 1 addition & 1 deletion src/OpenColorIO/ParseUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ StringUtils::StringVec SplitStringEnvStyle(const std::string & str)
const std::string s = StringUtils::Trim(str);
if( s.size() == 0 )
{
return {};
return { "" };
}

StringUtils::StringVec outputvec;
Expand Down
2 changes: 1 addition & 1 deletion tests/cpu/ParseUtils_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ OCIO_ADD_TEST(ParseUtils, split_string_env_style)
{
StringUtils::StringVec outputvec;
outputvec = OCIO::SplitStringEnvStyle("");
OCIO_CHECK_EQUAL(0, outputvec.size());
OCIO_CHECK_EQUAL(1, outputvec.size());
outputvec.clear();

outputvec = OCIO::SplitStringEnvStyle("This:is:a:test");
Expand Down
1 change: 1 addition & 0 deletions tests/cpu/ViewingRules_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ active_views: []

std::stringstream os;
os << *config.get();
OCIO_CHECK_EQUAL(0, config->getNumActiveDisplays());
OCIO_CHECK_EQUAL(os.str(), SIMPLE_CONFIG);

// Copy to set active views.
Expand Down

0 comments on commit 6df1d60

Please sign in to comment.