diff options
| author | Glenn Smith <glenn@vector35.com> | 2025-05-20 18:36:42 -0400 |
|---|---|---|
| committer | Glenn Smith <glenn@vector35.com> | 2025-05-22 15:09:32 -0400 |
| commit | 6458016449500151053964411398145244374352 (patch) | |
| tree | 0bccdae090d891591f5fa7844c7878f73c78e75e /type.cpp | |
| parent | 5094770405372098081110764843950364933904 (diff) | |
Add fmt printer for Ref<Type>
Diffstat (limited to 'type.cpp')
| -rw-r--r-- | type.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
@@ -1332,7 +1332,7 @@ bool Type::EnumerateTypesForAccess(BinaryView* data, uint64_t offset, size_t siz std::vector<TypeDefinitionLine> Type::GetLines(const TypeContainer& types, const std::string& name, - int paddingCols, bool collapsed, BNTokenEscapingType escaping) + int paddingCols, bool collapsed, BNTokenEscapingType escaping) const { size_t count; BNTypeDefinitionLine* list = @@ -3110,3 +3110,36 @@ bool BinaryNinja::PreprocessSource( delete[] includeDirList; return result; } + + +fmt::format_context::iterator fmt::formatter<BinaryNinja::Type>::format( + const Type& obj, + fmt::format_context& ctx +) const +{ + if (presentation == '?') + { + auto tc = TypeContainer::GetEmptyTypeContainer(); + auto lines = obj.GetLines(tc, ""); + + string result = ""; + for (auto& line: lines) + { + string lineStr = ""; + for (auto& token: line.tokens) + { + lineStr += token.text; + } + result += lineStr + "\n"; + } + // Remove trailing newline + if (!result.empty()) + result.erase(result.size() - 1); + return fmt::format_to(ctx.out(), "{}", result); + } + else + { + return fmt::format_to(ctx.out(), "{}{}", obj.GetStringBeforeName(), obj.GetStringAfterName()); + } +} + |
