Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/OpenColorIO/ColorSpaceSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ColorSpaceSet::Impl
// Search for name and aliases.
if (csName && *csName)
{
const std::string str = StringUtils::Lower(csName);
const std::string_view str(csName);
for (size_t idx = 0; idx < m_colorSpaces.size(); ++idx)
{
if (StringUtils::Compare(m_colorSpaces[idx]->getName(), str))
Expand Down Expand Up @@ -181,12 +181,10 @@ class ColorSpaceSet::Impl
void remove(const char * csName)
{
if (!csName || !*csName) return;
const std::string name = StringUtils::Lower(csName);
if (name.empty()) return;

for (auto itr = m_colorSpaces.begin(); itr != m_colorSpaces.end(); ++itr)
{
if (StringUtils::Lower((*itr)->getName())==name)
if (StringUtils::Compare((*itr)->getName(), csName))
{
m_colorSpaces.erase(itr);
return;
Expand Down
37 changes: 18 additions & 19 deletions src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,16 @@ class Config::Impl
{
if (name && *name)
{
const std::string str = StringUtils::Lower(name);
for (size_t idx = 0; idx < m_allNamedTransforms.size(); ++idx)
{
if (StringUtils::Lower(m_allNamedTransforms[idx]->getName()) == str)
if (StringUtils::Compare(m_allNamedTransforms[idx]->getName(), name))
{
return idx;
}
const auto numAliases = m_allNamedTransforms[idx]->getNumAliases();
for (size_t alias = 0; alias < numAliases; ++alias)
{
if (StringUtils::Lower(m_allNamedTransforms[idx]->getAlias(alias)) == str)
if (StringUtils::Compare(m_allNamedTransforms[idx]->getAlias(alias), name))
{
return idx;
}
Expand All @@ -551,11 +550,14 @@ class Config::Impl

ConstViewTransformRcPtr getViewTransform(const char * name) const noexcept
{
const std::string namelower = StringUtils::Lower(name);
if (!name)
{
return ConstViewTransformRcPtr();
}

for (const auto & vt : m_viewTransforms)
{
if (StringUtils::Lower(vt->getName()) == namelower)
if (StringUtils::Compare(vt->getName(), name))
{
return vt;
}
Expand All @@ -566,11 +568,14 @@ class Config::Impl

ConstLookRcPtr getLook(const char * name) const
{
const std::string namelower = StringUtils::Lower(name);
if (!name)
{
return ConstLookRcPtr();
}

for (const auto & look : m_looksList)
{
if (StringUtils::Lower(look->getName()) == namelower)
if (StringUtils::Compare(look->getName(), name))
{
return look;
}
Expand Down Expand Up @@ -907,7 +912,6 @@ class Config::Impl
viewNames = GetViewNames(views);
StringUtils::StringVec activeViews = getActiveViews(viewNames);

const std::string imageColorSpaceName{ StringUtils::Lower(imageCSName) };
StringUtils::StringVec filteredActiveViews;
for (const auto & view : activeViews)
{
Expand All @@ -929,8 +933,8 @@ class Config::Impl
const char * rolename = m_viewingRules->getColorSpace(ruleIdx, csIdx);
const char * csname = LookupRole(m_roles, rolename);

const std::string csName{ *csname ? csname : rolename };
if (StringUtils::Lower(csName) == imageColorSpaceName)
const char * csName = *csname ? csname : rolename;
if (StringUtils::Compare(csName, imageCSName))
{
// Include a view if its rule contains the image's color space.
filteredActiveViews.push_back(view);
Expand Down Expand Up @@ -3528,12 +3532,11 @@ void Config::addNamedTransform(const ConstNamedTransformRcPtr & nt)

void Config::removeNamedTransform(const char * name)
{
const std::string nameToSearch = StringUtils::Lower(name);
if (nameToSearch.empty()) return;
if (!name || !*name) return;

for (auto itr = getImpl()->m_allNamedTransforms.begin(); itr != getImpl()->m_allNamedTransforms.end(); ++itr)
{
if (StringUtils::Lower((*itr)->getName()) == nameToSearch)
if (StringUtils::Compare((*itr)->getName(), name))
{
getImpl()->m_allNamedTransforms.erase(itr);
return;
Expand Down Expand Up @@ -5112,12 +5115,10 @@ void Config::addLook(const ConstLookRcPtr & look)
if(name.empty())
throw Exception("Cannot addLook with an empty name.");

const std::string namelower = StringUtils::Lower(name);

// If the look exists, replace it
for(unsigned int i=0; i<getImpl()->m_looksList.size(); ++i)
{
if(StringUtils::Lower(getImpl()->m_looksList[i]->getName()) == namelower)
if(StringUtils::Compare(getImpl()->m_looksList[i]->getName(), name))
{
getImpl()->m_looksList[i] = look->createEditableCopy();

Expand Down Expand Up @@ -5221,14 +5222,12 @@ void Config::addViewTransform(const ConstViewTransformRcPtr & viewTransform)
throw Exception(os.str().c_str());
}

const std::string namelower = StringUtils::Lower(name);

bool addIt = true;

// If the view transform exists, replace it.
for (auto && vt : getImpl()->m_viewTransforms)
{
if (StringUtils::Lower(vt->getName()) == namelower)
if (StringUtils::Compare(vt->getName(), name))
{
vt = viewTransform->createEditableCopy();
addIt = false;
Expand Down
3 changes: 1 addition & 2 deletions src/OpenColorIO/ParseUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,9 @@ StringUtils::StringVec IntersectStringVecsCaseIgnore(const StringUtils::StringVe

int FindInStringVecCaseIgnore(const StringUtils::StringVec & vec, const std::string & str)
{
const std::string teststr = StringUtils::Lower(str);
for(unsigned int i=0; i<vec.size(); ++i)
{
if(StringUtils::Lower(vec[i]) == teststr) return static_cast<int>(i);
if(StringUtils::Compare(vec[i], str)) return static_cast<int>(i);
}

return -1;
Expand Down
21 changes: 6 additions & 15 deletions src/OpenColorIO/TokensManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ class TokensManager
if (!token || !*token) return m_tokens.end();

// NB: Categories are not case-sensitive and whitespace is stripped.
const std::string ref(StringUtils::Trim(StringUtils::Lower(token)));
// Stored tokens are already trimmed by addToken().
const std::string ref(StringUtils::Trim(token));

for (auto itr = m_tokens.begin(); itr != m_tokens.end(); ++itr)
{
if (StringUtils::Trim(StringUtils::Lower(*itr)) == ref)
if (StringUtils::Compare(*itr, ref))
{
return itr;
}
Expand All @@ -60,21 +61,11 @@ class TokensManager

void removeToken(const char * token) noexcept
{
if (!token || !*token) return;

// NB: Categories are not case-sensitive and whitespace is stripped.
const std::string ref(StringUtils::Trim(StringUtils::Lower(token)));

for (auto itr = m_tokens.begin(); itr != m_tokens.end(); ++itr)
const auto itr = findToken(token);
if (itr != m_tokens.end())
{
if (StringUtils::Trim(StringUtils::Lower(*itr)) == ref)
{
m_tokens.erase(itr);
return;
}
m_tokens.erase(itr);
}

return;
}

int getNumTokens() const noexcept
Expand Down
4 changes: 1 addition & 3 deletions src/OpenColorIO/ViewingRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ namespace
{
bool IsEncodingUsed(const ColorSpaceSetRcPtr & colorspaces, const char * encName)
{
const std::string teststr = StringUtils::Lower(encName);
const int numCS = colorspaces->getNumColorSpaces();
for (int cs = 0; cs < numCS; ++cs)
{
auto colorspace = colorspaces->getColorSpaceByIndex(cs);
const std::string csis{ colorspace->getEncoding() };
if (StringUtils::Lower(csis) == teststr)
if (StringUtils::Compare(colorspace->getEncoding(), encName))
{
return true;
}
Expand Down
18 changes: 16 additions & 2 deletions src/utils/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <iterator>
#include <sstream>
#include <string>
#include <string_view>
#include <vector>


Expand Down Expand Up @@ -82,9 +83,22 @@ inline std::string Upper(const char * str)
}

// Case insensitive comparison of strings.
inline bool Compare(const std::string & left, const std::string & right)
inline bool Compare(std::string_view left, std::string_view right)
{
return Lower(left) == Lower(right);
if (left.size() != right.size())
{
return false;
}

// Manual comparison by character to avoid std::string allocation overhead.
for (size_t i = 0; i < left.size(); ++i)
{
if (Lower((unsigned char)left[i]) != Lower((unsigned char)right[i]))
{
return false;
}
}
return true;
}

// Return true if the string ends with the suffix.
Expand Down
Loading