From 6bb5a81cee7e76e8a4e69f7f49869f39c1c382f0 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 5 Sep 2023 14:45:51 +0200 Subject: Adds some convenience methods. fl_filename_absolute can no generate a path using arbitrary source paths. Fl_Menu_ adds find_item_with_user_data and find_item_with_argument Fl_String adds find(string, start) --- src/Fl_String.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/Fl_String.cxx') diff --git a/src/Fl_String.cxx b/src/Fl_String.cxx index 693a88286..e285519ff 100644 --- a/src/Fl_String.cxx +++ b/src/Fl_String.cxx @@ -465,6 +465,21 @@ Fl_String &Fl_String::operator+=(char c) { return append(c); } +/** + Find a string inside this string. + \param[in] needle find this string + \param[in] start_pos start looking at this position + \return the offset of the text inside this string, if it was found + \return Fl_String::npos if the needle was not found + */ +int Fl_String::find(const Fl_String &needle, int start_pos) const { + if ((start_pos < 0) || (start_pos >= size_)) return npos; + const char *haystack = data() + start_pos; + const char *found = strstr(haystack, needle.c_str()); + if (!found) return npos; + return (int)(found - data()); +} + /** Replace part of the string with a C-style string or data. \param[in] at erase and insert at this index -- cgit v1.2.3