From 6a1979c5e502d1403cbccf122b6dab8dd05b3c63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jarkko=20P=C3=B6yry?= Date: Wed, 18 Mar 2015 19:57:23 -0700 Subject: [PATCH] Add beginsWith/endsWith to deStringUtil.hpp. Change-Id: Id538b11e6cd8b717f814166a6497c500e12a675b --- framework/delibs/decpp/deStringUtil.cpp | 36 ++++++++++++++++++++++ framework/delibs/decpp/deStringUtil.hpp | 2 ++ .../functional/es31fProgramInterfaceDefinition.cpp | 3 +- .../es31fProgramInterfaceQueryTestCase.cpp | 10 +----- .../functional/es31fProgramInterfaceQueryTests.cpp | 12 ++------ 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/framework/delibs/decpp/deStringUtil.cpp b/framework/delibs/decpp/deStringUtil.cpp index c5e0166..14fccaa 100644 --- a/framework/delibs/decpp/deStringUtil.cpp +++ b/framework/delibs/decpp/deStringUtil.cpp @@ -22,6 +22,7 @@ *//*--------------------------------------------------------------------*/ #include "deStringUtil.hpp" +#include "deString.h" #include #include @@ -113,6 +114,22 @@ std::string floatToString (float val, int precision) return s.str(); } +bool beginsWith (const std::string& s, const std::string& prefix) +{ + return deStringBeginsWith(s.c_str(), prefix.c_str()); +} + +bool endsWith (const std::string& s, const std::string& suffix) +{ + if (suffix.length() > s.length()) + return false; + else + { + const std::string::size_type offset = s.length() - suffix.length(); + return s.find(suffix, offset) == offset; + } +} + char toUpper (char c) { return std::toupper(c, std::locale::classic()); @@ -156,6 +173,25 @@ void StringUtil_selfTest (void) DE_TEST_ASSERT(floatToString(4, 1) == "4.0"); + DE_TEST_ASSERT(beginsWith("foobar", "foobar")); + DE_TEST_ASSERT(beginsWith("foobar", "foo")); + DE_TEST_ASSERT(beginsWith("foobar", "f")); + DE_TEST_ASSERT(beginsWith("foobar", "")); + DE_TEST_ASSERT(beginsWith("", "")); + DE_TEST_ASSERT(!beginsWith("foobar", "bar")); + DE_TEST_ASSERT(!beginsWith("foobar", "foobarbaz")); + DE_TEST_ASSERT(!beginsWith("", "foo")); + + DE_TEST_ASSERT(endsWith("foobar", "foobar")); + DE_TEST_ASSERT(endsWith("foobar", "bar")); + DE_TEST_ASSERT(endsWith("foobar", "r")); + DE_TEST_ASSERT(endsWith("foobar", "")); + DE_TEST_ASSERT(endsWith("", "")); + DE_TEST_ASSERT(!endsWith("foobar", "foo")); + DE_TEST_ASSERT(!endsWith("foobar", "bazfoobar")); + DE_TEST_ASSERT(!endsWith("foobar", "foobarbaz")); + DE_TEST_ASSERT(!endsWith("", "foo")); + DE_TEST_ASSERT(toUpper('a') == 'A'); DE_TEST_ASSERT(toUpper('A') == 'A'); DE_TEST_ASSERT(toLower('a') == 'a'); diff --git a/framework/delibs/decpp/deStringUtil.hpp b/framework/delibs/decpp/deStringUtil.hpp index 68614d8..343619c 100644 --- a/framework/delibs/decpp/deStringUtil.hpp +++ b/framework/delibs/decpp/deStringUtil.hpp @@ -47,6 +47,8 @@ std::string toUpper (const std::string& s); std::string capitalize (const std::string& s); std::vector splitString (const std::string& s, char delim='\0'); std::string floatToString (float val, int precision); +bool beginsWith (const std::string& s, const std::string& prefix); +bool endsWith (const std::string& s, const std::string& suffix); char toUpper (char c); char toLower (char c); bool isUpper (char c); diff --git a/modules/gles31/functional/es31fProgramInterfaceDefinition.cpp b/modules/gles31/functional/es31fProgramInterfaceDefinition.cpp index 88ae724..6d8f737 100644 --- a/modules/gles31/functional/es31fProgramInterfaceDefinition.cpp +++ b/modules/gles31/functional/es31fProgramInterfaceDefinition.cpp @@ -26,6 +26,7 @@ #include "gluVarType.hpp" #include "gluShaderProgram.hpp" #include "deSTLUtil.hpp" +#include "deStringUtil.hpp" #include "glwEnums.hpp" #include @@ -634,7 +635,7 @@ bool Program::isValid (void) const for (int ndx = 0; ndx < (int)m_xfbVaryings.size(); ++ndx) { // user-defined - if (m_xfbVaryings[ndx].find("gl_") != 0) + if (!de::beginsWith(m_xfbVaryings[ndx], "gl_")) { std::vector path; if (!findProgramVariablePathByPathName(path, this, m_xfbVaryings[ndx], VariableSearchFilter::createShaderTypeStorageFilter(getProgramTransformFeedbackStage(this), glu::STORAGE_OUT))) diff --git a/modules/gles31/functional/es31fProgramInterfaceQueryTestCase.cpp b/modules/gles31/functional/es31fProgramInterfaceQueryTestCase.cpp index 15c6431..778ef6f 100644 --- a/modules/gles31/functional/es31fProgramInterfaceQueryTestCase.cpp +++ b/modules/gles31/functional/es31fProgramInterfaceQueryTestCase.cpp @@ -46,14 +46,6 @@ namespace using ProgramInterfaceDefinition::VariablePathComponent; using ProgramInterfaceDefinition::VariableSearchFilter; -static bool stringEndsWith (const std::string& str, const std::string& suffix) -{ - if (suffix.length() > str.length()) - return false; - else - return str.substr(str.length() - suffix.length()) == suffix; -} - static glw::GLenum getProgramDefaultBlockInterfaceFromStorage (glu::Storage storage) { switch (storage) @@ -1966,7 +1958,7 @@ static void queryAndValidateProps (tcu::TestContext& testCtx, if (recoveryStrategies[strategyNdx].removeTrailingArray) { - if (stringEndsWith(resourceName, "[0]")) + if (de::endsWith(resourceName, "[0]")) simplifiedResourceName = resourceName.substr(0, resourceName.length() - 3); else continue; diff --git a/modules/gles31/functional/es31fProgramInterfaceQueryTests.cpp b/modules/gles31/functional/es31fProgramInterfaceQueryTests.cpp index 0bc1efc..bfc85d9 100644 --- a/modules/gles31/functional/es31fProgramInterfaceQueryTests.cpp +++ b/modules/gles31/functional/es31fProgramInterfaceQueryTests.cpp @@ -52,14 +52,6 @@ namespace Functional namespace { -static bool stringEndsWith (const std::string& str, const std::string& suffix) -{ - if (suffix.length() > str.length()) - return false; - else - return str.substr(str.length() - suffix.length()) == suffix; -} - static int getTypeSize (glu::DataType type) { if (type == glu::TYPE_FLOAT) @@ -1106,7 +1098,7 @@ bool ResourceListTestCase::verifyResourceIndexQuery (const std::vector