@@ -447,7 +447,7 @@ void addBuiltinTypes(Model model) {
447447 auto build_rust_type = [&](clang::QualType qt) {
448448 unsigned bits = ctx_->getTypeSize (qt);
449449 char sign = qt->isSignedIntegerType () ? ' i' : ' u' ;
450- return std::string ( 1 , sign) + std::to_string ( bits);
450+ return std::format ( " {}{} " , sign, bits);
451451 };
452452
453453 // Misc
@@ -547,13 +547,14 @@ std::string mapTypeStringRecursive(const std::string &cpp_type) {
547547}
548548
549549std::string normalizeTranslationRule (std::string rule) {
550- const std::array<std::pair<std::regex, std::string>, 2 > normalization_rules{{
551- // Dettach pointer from double reference. Useful for matching translation
552- // rules.
553- {std::regex (R"( \*\&\&)" ), " * &&" },
554- // Ignore constant template parameters, i.e. replace them with _.
555- {std::regex (R"( \b\d+\b)" ), " _" },
556- }};
550+ static const std::array<std::pair<std::regex, std::string>, 2 >
551+ normalization_rules{{
552+ // Dettach pointer from double reference. Useful for matching
553+ // translation rules.
554+ {std::regex (R"( \*\&\&)" ), " * &&" },
555+ // Ignore constant template parameters, i.e. replace them with _.
556+ {std::regex (R"( \b\d+\b)" ), " _" },
557+ }};
557558
558559 for (const auto &r : normalization_rules) {
559560 rule = std::regex_replace (rule, r.first , r.second );
@@ -567,7 +568,7 @@ static std::string synthesizeAnonRecordName(const clang::RecordDecl *record) {
567568 if (auto *parent =
568569 clang::dyn_cast<clang::RecordDecl>(record->getDeclContext ())) {
569570 parent_name = parent->getIdentifier ()
570- ? parent->getIdentifier ()->getName (). str ( )
571+ ? std::string ( parent->getIdentifier ()->getName ())
571572 : synthesizeAnonRecordName (parent);
572573 parent_name += ' _' ;
573574 }
@@ -674,7 +675,7 @@ bool ParamIsPointer(const clang::Expr *expr, unsigned index) {
674675
675676void AddRuleForUserDefinedType (clang::NamedDecl *decl) {
676677 auto cpp_name = ToString (decl);
677- auto rs_name = std::regex_replace (cpp_name, std::regex ( " ::" ) , " _" );
678+ auto rs_name = ReplaceAll (cpp_name, " ::" , " _" );
678679
679680 if (types_.contains (cpp_name)) {
680681 return ;
@@ -863,10 +864,11 @@ std::string ToString(const clang::Expr *expr) {
863864 }
864865
865866 if (const auto *uop = llvm::dyn_cast<clang::UnaryOperator>(expr)) {
866- std::string opcode =
867- clang::UnaryOperator::getOpcodeStr (uop->getOpcode ()).str ();
868- return uop->isPostfix () ? ToString (uop->getSubExpr ()) + std::move (opcode)
869- : std::move (opcode) + ToString (uop->getSubExpr ());
867+ auto sub = ToString (uop->getSubExpr ());
868+ std::string_view opcode =
869+ clang::UnaryOperator::getOpcodeStr (uop->getOpcode ());
870+ return uop->isPostfix () ? std::format (" {}{}" , sub, opcode)
871+ : std::format (" {}{}" , opcode, sub);
870872 }
871873
872874 return " Unhandled case in ToString" ;
0 commit comments