openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

feature: string starts and ends with functions

Open thomasgeissl opened this issue 3 years ago • 0 comments

I find myself always adding little string helper functions. I think startsWith and endsWith will be added for cpp20.

does it make sense to add something like this to the core?

//ofEndsWith
static bool ofDoesStringEndWith(const std::string &str, const std::string &suffix)
{
    return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
}
//ofStartsWith
static bool ofDoesStringStartWith(const std::string &str, const std::string &prefix)
{
    return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix);
}

t

thomasgeissl avatar Aug 19 '22 10:08 thomasgeissl