add get_name_prefix

This commit is contained in:
David Rose 2008-10-11 15:29:51 +00:00
parent 64d24fb65b
commit bc2dcf0410
2 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -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;