refactor collada: Added utility functions bc_string_before() and bc_string_after()
This commit is contained in:
parent
820e4d4303
commit
0731b88ddb
|
@ -132,7 +132,31 @@ const bool BCAnimationCurve::is_of_animation_type(BC_animation_type type) const
|
|||
const std::string BCAnimationCurve::get_channel_target() const
|
||||
{
|
||||
const std::string path = curve_key.get_path();
|
||||
return bc_string_after(path, '.');
|
||||
|
||||
if (bc_startswith(path, "pose.bones")) {
|
||||
return bc_string_after(path, "pose.bones");
|
||||
}
|
||||
return bc_string_after(path, ".");
|
||||
}
|
||||
|
||||
const std::string BCAnimationCurve::get_channel_type() const
|
||||
{
|
||||
const std::string channel = get_channel_target();
|
||||
return bc_string_after(channel, ".");
|
||||
}
|
||||
|
||||
const std::string BCAnimationCurve::get_channel_posebone() const
|
||||
{
|
||||
const std::string channel = get_channel_target();
|
||||
std::string pose_bone_name = bc_string_before(channel, ".");
|
||||
if (pose_bone_name == channel) {
|
||||
pose_bone_name = "";
|
||||
}
|
||||
else {
|
||||
pose_bone_name = bc_string_after(pose_bone_name, "\"[");
|
||||
pose_bone_name = bc_string_before(pose_bone_name, "]\"");
|
||||
}
|
||||
return pose_bone_name;
|
||||
}
|
||||
|
||||
const std::string BCAnimationCurve::get_animation_name(Object *ob) const
|
||||
|
|
|
@ -160,11 +160,20 @@ extern int bc_get_active_UVLayer(Object *ob);
|
|||
|
||||
std::string bc_find_bonename_in_path(std::string path, std::string probe);
|
||||
|
||||
inline std::string bc_string_after(const std::string &s, const char c)
|
||||
inline std::string bc_string_after(const std::string &s, const std::string probe)
|
||||
{
|
||||
size_t i = s.rfind(c, s.length());
|
||||
size_t i = s.rfind(probe);
|
||||
if (i != std::string::npos) {
|
||||
return (s.substr(i + 1, s.length() - i));
|
||||
return (s.substr(i + probe.length(), s.length() - i));
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
|
||||
inline std::string bc_string_before(const std::string &s, const std::string probe)
|
||||
{
|
||||
size_t i = s.find(probe);
|
||||
if (i != std::string::npos) {
|
||||
return s.substr(0, i);
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
|
@ -177,6 +186,14 @@ inline bool bc_startswith(std::string const &value, std::string const &starting)
|
|||
return (value.substr(0, starting.size()) == starting);
|
||||
}
|
||||
|
||||
inline bool bc_endswith(const std::string &value, const std::string &ending)
|
||||
{
|
||||
if (ending.size() > value.size())
|
||||
return false;
|
||||
|
||||
return value.compare(value.size() - ending.size(), ending.size(), ending) == 0;
|
||||
}
|
||||
|
||||
#if 0 /* UNUSED */
|
||||
inline bool bc_endswith(std::string const &value, std::string const &ending)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue