<commit_before>using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.AST;
using CppSharp.Generators.CLI;
using CppSharp.Generators.CSharp;

namespace CppSharp.Types.Std
{
    [TypeMap("va_list")]
    public class VaList : TypeMap
    {
        public override string CLISignature(CLITypePrinterContext ctx)
        {
            return "va_list";
        }

        public override string CSharpSignature(CSharpTypePrinterContext ctx)
        {
            return "va_list";
        }

        public override bool IsIgnored
        {
            get { return true; }
        }
    }

    [TypeMap("std::basic_string<char, std::char_traits<char>, std::allocator<char>>")]
    public class String : TypeMap
    {
        public override string CLISignature(CLITypePrinterContext ctx)
        {
            return "System::String^";
        }

        public override void CLIMarshalToNative(MarshalContext ctx)
        {
            ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0})",
                ctx.Parameter.Name);
        }

        public override void CLIMarshalToManaged(MarshalContext ctx)
        {
            ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0})",
                ctx.ReturnVarName);
        }

        public override string CSharpSignature(CSharpTypePrinterContext ctx)
        {
            if (ctx.CSharpKind == CSharpTypePrinterContextKind.Managed)
                return "string";
            ClassTemplateSpecialization basicString = GetBasicString(ctx.Type);
            var typePrinter = new CSharpTypePrinter(null);
            typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
            return basicString.Visit(typePrinter).Type;
        }

        public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
        {
            var type = ctx.Parameter.Type.Desugar();
            ClassTemplateSpecialization basicString = GetBasicString(type);
            var typePrinter = new CSharpTypePrinter(ctx.Driver);
            typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
            if (!ctx.Parameter.Type.Desugar().IsAddress())
                ctx.Return.Write("*({0}*) ", basicString.Visit(typePrinter));
            typePrinter.PopContext();
            var allocator = ctx.Driver.ASTContext.FindClass("allocator", false, true).First(
                a => a.IsSupportedStdType());
            if (type.IsPointer() || (type.IsReference() && ctx.Declaration is Field))
            {
                ctx.Return.Write("new {0}({1}, new {2}()).{3}",
                    basicString.Visit(typePrinter), ctx.Parameter.Name,
                    allocator.Visit(typePrinter), Helpers.InstanceIdentifier);
            }
            else
            {
                string varBasicString = "__basicString" + ctx.ParameterIndex;
                ctx.SupportBefore.WriteLine("using (var {0} = new {1}({2}, new {3}()))",
                    varBasicString, basicString.Visit(typePrinter),
                    ctx.Parameter.Name, allocator.Visit(typePrinter));
                ctx.SupportBefore.WriteStartBraceIndent();
                ctx.Return.Write("{0}.{1}", varBasicString, Helpers.InstanceIdentifier);
                ctx.HasCodeBlock = true;
            }
        }

        public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
        {
            var type = ctx.ReturnType.Type;
            ClassTemplateSpecialization basicString = GetBasicString(type);
            var c_str = basicString.Methods.First(m => m.OriginalName == "c_str");<commit_msg>Fixed the type map for std::string to also destroy the allocator.<commit_after>using System.Linq;
using CppSharp.AST;
using CppSharp.AST.Extensions;
using CppSharp.Generators;
using CppSharp.Generators.AST;
using CppSharp.Generators.CLI;
using CppSharp.Generators.CSharp;

namespace CppSharp.Types.Std
{
    [TypeMap("va_list")]
    public class VaList : TypeMap
    {
        public override string CLISignature(CLITypePrinterContext ctx)
        {
            return "va_list";
        }

        public override string CSharpSignature(CSharpTypePrinterContext ctx)
        {
            return "va_list";
        }

        public override bool IsIgnored
        {
            get { return true; }
        }
    }

    [TypeMap("std::basic_string<char, std::char_traits<char>, std::allocator<char>>")]
    public class String : TypeMap
    {
        public override string CLISignature(CLITypePrinterContext ctx)
        {
            return "System::String^";
        }

        public override void CLIMarshalToNative(MarshalContext ctx)
        {
            ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0})",
                ctx.Parameter.Name);
        }

        public override void CLIMarshalToManaged(MarshalContext ctx)
        {
            ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0})",
                ctx.ReturnVarName);
        }

        public override string CSharpSignature(CSharpTypePrinterContext ctx)
        {
            if (ctx.CSharpKind == CSharpTypePrinterContextKind.Managed)
                return "string";
            ClassTemplateSpecialization basicString = GetBasicString(ctx.Type);
            var typePrinter = new CSharpTypePrinter(null);
            typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
            return basicString.Visit(typePrinter).Type;
        }

        public override void CSharpMarshalToNative(CSharpMarshalContext ctx)
        {
            var type = ctx.Parameter.Type.Desugar();
            ClassTemplateSpecialization basicString = GetBasicString(type);
            var typePrinter = new CSharpTypePrinter(ctx.Driver);
            typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
            if (!ctx.Parameter.Type.Desugar().IsAddress())
                ctx.Return.Write("*({0}*) ", basicString.Visit(typePrinter));
            typePrinter.PopContext();
            var allocator = ctx.Driver.ASTContext.FindClass("allocator", false, true).First(
                a => a.IsSupportedStdType());
            if (type.IsPointer() || (type.IsReference() && ctx.Declaration is Field))
            {
                ctx.Return.Write("new {0}({1}, new {2}()).{3}",
                    basicString.Visit(typePrinter), ctx.Parameter.Name,
                    allocator.Visit(typePrinter), Helpers.InstanceIdentifier);
            }
            else
            {
                string varAllocator = "__allocator" + ctx.ParameterIndex;
                string varBasicString = "__basicString" + ctx.ParameterIndex;
                ctx.SupportBefore.WriteLine("using (var {0} = new {1}())",
                    varAllocator, allocator.Visit(typePrinter));
                ctx.SupportBefore.WriteLine("using (var {0} = new {1}({2}, {3}))",
                    varBasicString, basicString.Visit(typePrinter),
                    ctx.Parameter.Name, varAllocator);
                ctx.SupportBefore.WriteStartBraceIndent();
                ctx.Return.Write("{0}.{1}", varBasicString, Helpers.InstanceIdentifier);
                ctx.HasCodeBlock = true;
            }
        }

        public override void CSharpMarshalToManaged(CSharpMarshalContext ctx)
        {
            var type = ctx.ReturnType.Type;
            ClassTemplateSpecialization basicString = GetBasicString(type);
            var c_str = basicString.Methods.First(m => m.OriginalName == "c_str");
{'fraction_non_alphanumeric': 0.10466666666666667, 'fraction_numerical': 0.004266666666666667, 'mean_word_length': 2.235979292493529, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '344398', 'n_tokens_mistral': 2102, 'n_tokens_neox': 1987, 'n_words': 359}