mv is_object to Util.i

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry
2026-05-07 11:11:32 -07:00
parent 6eb6911d30
commit 7e68e452d3
2 changed files with 35 additions and 39 deletions

View File

@@ -265,45 +265,6 @@ using namespace sta;
%}
////////////////////////////////////////////////////////////////
%inline %{
bool
is_object(const char *obj)
{
// _hexaddress_p_type
const std::string s(obj);
if (s.empty() || s[0] != '_')
return false;
const size_t hex_digits = sizeof(void *) * 2;
if (s.size() < 1 + hex_digits + 3)
return false;
for (size_t i = 1; i < 1 + hex_digits; i++) {
if (!std::isxdigit(static_cast<unsigned char>(s[i])))
return false;
}
if (s.compare(1 + hex_digits, 3, "_p_") != 0)
return false;
for (size_t i = 1 + hex_digits + 3; i < s.size(); i++) {
char ch = s[i];
if (!(std::isalnum(ch) || ch == '_'))
return false;
}
return true;
}
// Assumes is_object is true.
const char *
object_type(const char *obj)
{
if (is_object(obj))
return &obj[1 + sizeof(void*) * 2 + 3];
return "";
}
%}
////////////////////////////////////////////////////////////////
//
// SWIG type definitions.

View File

@@ -504,4 +504,39 @@ fuzzy_equal(float value1,
return fuzzyEqual(value1, value2);
}
////////////////////////////////////////////////////////////////
bool
is_object(const char *obj)
{
// _hexaddress_p_type
const std::string s(obj);
if (s.empty() || s[0] != '_')
return false;
const size_t hex_digits = sizeof(void *) * 2;
if (s.size() < 1 + hex_digits + 3)
return false;
for (size_t i = 1; i < 1 + hex_digits; i++) {
if (!std::isxdigit(static_cast<unsigned char>(s[i])))
return false;
}
if (s.compare(1 + hex_digits, 3, "_p_") != 0)
return false;
for (size_t i = 1 + hex_digits + 3; i < s.size(); i++) {
char ch = s[i];
if (!(std::isalnum(ch) || ch == '_'))
return false;
}
return true;
}
// Assumes is_object is true.
const char *
object_type(const char *obj)
{
if (is_object(obj))
return &obj[1 + sizeof(void*) * 2 + 3];
return "";
}
%} // inline