David Rose 17 лет назад
Родитель
Сommit
bc2dcf0410
2 измененных файлов с 29 добавлено и 0 удалено
  1. 28 0
      panda/src/event/asyncTask.cxx
  2. 1 0
      panda/src/event/asyncTask.h

+ 28 - 0
panda/src/event/asyncTask.cxx

@@ -177,6 +177,34 @@ set_name(const string &name) {
 #endif  // DO_PSTATS
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: AsyncTask::get_name_prefix
+//       Access: Published
+//  Description: Returns the initial part of the name, up to but not
+//               including any trailing digits following a hyphen or
+//               underscore.
+////////////////////////////////////////////////////////////////////
+string AsyncTask::
+get_name_prefix() const {
+  string name = get_name();
+  size_t trimmed = name.size();
+  size_t p = trimmed;
+  while (true) {
+    while (p > 0 && isdigit(name[p - 1])) {
+      --p;
+    }
+    if (p > 0 && (name[p - 1] == '-' || name[p - 1] == '_')) {
+      --p;
+      trimmed = p;
+    } else {
+      p = trimmed;
+      break;
+    }
+  }
+
+  return name.substr(0, trimmed);
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: AsyncTask::set_task_chain
 //       Access: Published

+ 1 - 0
panda/src/event/asyncTask.h

@@ -86,6 +86,7 @@ PUBLISHED:
 
   void set_name(const string &name);
   INLINE void clear_name();
+  string get_name_prefix() const;
 
   INLINE AtomicAdjust::Integer get_task_id() const;