summaryrefslogtreecommitdiff
path: root/src/Fl_String.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <github@matthiasm.com>2023-09-05 14:45:51 +0200
committerMatthias Melcher <github@matthiasm.com>2023-09-05 14:45:57 +0200
commit6bb5a81cee7e76e8a4e69f7f49869f39c1c382f0 (patch)
tree2a6d6f73dd19dd52aaccd1d99b50a20bb53946d6 /src/Fl_String.cxx
parentb2a41e08c3b9b5fbbd0c899537611b8e28e5993d (diff)
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)
Diffstat (limited to 'src/Fl_String.cxx')
-rw-r--r--src/Fl_String.cxx15
1 files changed, 15 insertions, 0 deletions
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
@@ -466,6 +466,21 @@ Fl_String &Fl_String::operator+=(char 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
\param[in] n_del number of bytes to erase