diff --git a/src/lib/format-obj.cpp b/src/lib/format-obj.cpp index 133991391..bbc84c24e 100644 --- a/src/lib/format-obj.cpp +++ b/src/lib/format-obj.cpp @@ -83,8 +83,12 @@ namespace meta { // pre-allocated failure indicators, which can be returned failsafe. - extern const std::string FAILURE_INDICATOR = "↯"; - extern const std::string VOID_INDICATOR = "void"; + extern const string FAILURE_INDICATOR = "↯"; + extern const string VOID_INDICATOR = "void"; + extern const string FUNCTION_INDICATOR= "Function"; + + extern const string BOOL_FALSE_STR = "false"; + extern const string BOOL_TRUE_STR = "true"; @@ -199,6 +203,7 @@ apologies for that." "|proc::play::" "|gui::model" "|gui::ctrl" + "|lumiera::" , regex::ECMAScript | regex::optimize}; static regex stdAllocator {"(\\w+<(\\w+)), allocator<\\2>\\s*" @@ -250,6 +255,7 @@ apologies for that." removeSuffix (typeStr, "&"); if (isnil (typeStr)) return VOID_INDICATOR; + if (')' == typeStr.back()) return FUNCTION_INDICATOR; auto end = typeStr.end(); auto beg = typeStr.begin(); @@ -277,19 +283,29 @@ apologies for that." string - sanitisedFullTypeName(lib::Literal rawName) + sanitisedFullTypeName (lib::Literal rawName) { return util::sanitise (humanReadableTypeID (rawName)); } + string + sanitisedSymbol (string const& text) + { + static regex identifierChars {"[A-Za-z]\\w*", regex::ECMAScript | regex::optimize}; + + return regex_replace (text, identifierChars, "$&", std::regex_constants::format_no_copy); + } + + + }}// namespace lib::meta -/* === formatting and pretty printing support uitls === */ +/* === formatting and pretty printing support utils === */ namespace util { diff --git a/src/lib/format-obj.hpp b/src/lib/format-obj.hpp index 35addbbd4..9e5c803dc 100644 --- a/src/lib/format-obj.hpp +++ b/src/lib/format-obj.hpp @@ -84,7 +84,7 @@ namespace meta { namespace util { std::string showDouble (double) noexcept; - std::string showFloat (float) noexcept; + std::string showFloat (float) noexcept; std::string showAddr (void const* addr) noexcept; /** preconfigured format for pretty-printing of addresses */ @@ -135,6 +135,15 @@ namespace util { return util::showFloat (val); } }; + template<> + struct StringConv + { + static std::string + invoke (bool val) noexcept + { + return util::showBool (val); + } + }; diff --git a/src/lib/meta/util.hpp b/src/lib/meta/util.hpp index 26e3997b1..8c13b3822 100644 --- a/src/lib/meta/util.hpp +++ b/src/lib/meta/util.hpp @@ -199,6 +199,12 @@ namespace meta { /** build a sanitised ID from full type name */ std::string sanitisedFullTypeName(lib::Literal); + /** condense a string and retain only valid identifiers + * @return string starting with letter, followed by + * letters, digits and underscore + */ + std::string sanitisedSymbol(std::string const&); + /** reverse the effect of C++ name mangling. * @return string in language-level form of a C++ type or object name, * or a string with the original input if demangling fails. @@ -211,9 +217,12 @@ namespace meta { std::string demangleCxx (lib::Literal rawName); + extern const std::string FUNCTION_INDICATOR; extern const std::string FAILURE_INDICATOR; extern const std::string VOID_INDICATOR; + extern const std::string BOOL_FALSE_STR; + extern const std::string BOOL_TRUE_STR; /** failsafe human readable type display @@ -354,6 +363,16 @@ namespace util { : "⟂ «" + typeStr(ptr) + "»"; } + /** human readable display of boolean values + * @return "`true`" or "`false`" + */ + inline std::string + showBool (bool yes) noexcept + { + return yes? lib::meta::BOOL_TRUE_STR + : lib::meta::BOOL_FALSE_STR; + } + }// namespace util diff --git a/src/lib/util.hpp b/src/lib/util.hpp index ecef0d548..c59675059 100644 --- a/src/lib/util.hpp +++ b/src/lib/util.hpp @@ -347,6 +347,7 @@ namespace util { "Bääääh!!" --> 'Bh' \endverbatim * @see sanitised-identifier-test.cpp + * @see lib::meta::sanitisedSymbol() */ string sanitise (string const& org); diff --git a/tests/library/meta/type-display-test.cpp b/tests/library/meta/type-display-test.cpp index 73a5a864a..57a3405c4 100644 --- a/tests/library/meta/type-display-test.cpp +++ b/tests/library/meta/type-display-test.cpp @@ -112,6 +112,8 @@ namespace test{ cout << typeSymbol(&magic) <::Inner>() <