Review: string routine drives me crazy (issue194067)


larry...@...
 

Reviewers: ,

Description:
Many times I've been plagued by inexplicable crashes in loadshader.cpp,
right at the call to boost::starts_with. I've wasted hours and hours
and been unable to figure out why it boost::startswith(x,y) should fail
when x and y are valid std::strings. So I finally wrote my own
(trivially) just to see if that happens, and I no longer crash. (Making
me able to move on to the real crash I'm supposed to be debugging. :-)


Please review this at http://codereview.appspot.com/194067/show

Affected files:
src/liboslexec/loadshader.cpp


Index: src/liboslexec/loadshader.cpp
===================================================================
--- src/liboslexec/loadshader.cpp (revision 544)
+++ src/liboslexec/loadshader.cpp (working copy)
@@ -232,13 +232,21 @@



+inline bool
+starts_with (const std::string &source, const std::string &pattern)
+{
+ return ! strncmp (source.c_str(), pattern.c_str(), pattern.length());
+}
+
+
+
// If the string 'source' begins with 'pattern', erase the pattern from
// the start of source and return true. Otherwise, do not alter source
// and return false.
inline bool
extract_prefix (std::string &source, const std::string &pattern)
{
- if (boost::starts_with (source, pattern)) {
+ if (starts_with (source, pattern)) {
source.erase (0, pattern.length());
return true;
}

Join osl-dev@lists.aswf.io to automatically receive all group messages.