<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using Pchp.Core;
using Pchp.Library;
using Pchp.Library.Streams;

namespace Peachpie.Library.XmlDom
{
    /// <summary>
    /// This extension represents a writer that provides a non-cached, forward-only means of generating
    /// streams or files containing XML data.
    /// </summary>
    [PhpType(PhpTypeAttribute.InheritName), PhpExtension("xmlwriter")]
    public class XMLWriter : IDisposable
    {
        #region Constants

        private const string DefaultXmlVersion = "1.0";

        #endregion

        #region Fields and properties

        System.Xml.XmlWriter _writer;
        MemoryStream _memoryStream;
        PhpStream _uriPhpStream;

        // Counts nodes created in Comment, PI or CData section in order to close them properly in endComment/Pi/Cdata method.
        private int _unclosedNodesCount = 0;
        // It checks if Dtd section is empty. 
        private bool _dtdStart = false;

        // The State represents a section, where the xmlwriter is situated. e.g. When you call startComment, the xmlwriter changes its state to Comment
        private enum State 
        {
            Comment, 
            PI, // Processing instruction
            CDATA, 
            DTD, 
            DtdElement, 
            DtdEntity, 
            DtdAttlist 
        }

        // There can be actually two levels, where the state of xmlwriter can be situated. You can move to DtdElement if you are in DTD and you can move to CDATA if you are in PI.
        Stack<State> _state = new Stack<State>(2);

        static XmlWriterSettings DefaultSettings = new XmlWriterSettings()
        {
            Encoding = new UTF8Encoding(false),     // Disable BOM
            Indent = false,
            NewLineChars = "\n",
            WriteEndDocumentOnClose = true,
            ConformanceLevel = ConformanceLevel.Auto
        };

        #endregion

        public void Dispose()
        {
            _writer?.Dispose();<commit_msg>XmlWriter - Dispose() method not in PHP context<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using Pchp.Core;
using Pchp.Library;
using Pchp.Library.Streams;

namespace Peachpie.Library.XmlDom
{
    /// <summary>
    /// This extension represents a writer that provides a non-cached, forward-only means of generating
    /// streams or files containing XML data.
    /// </summary>
    [PhpType(PhpTypeAttribute.InheritName), PhpExtension("xmlwriter")]
    public class XMLWriter : IDisposable
    {
        #region Constants

        private const string DefaultXmlVersion = "1.0";

        #endregion

        #region Fields and properties

        System.Xml.XmlWriter _writer;
        MemoryStream _memoryStream;
        PhpStream _uriPhpStream;

        // Counts nodes created in Comment, PI or CData section in order to close them properly in endComment/Pi/Cdata method.
        private int _unclosedNodesCount = 0;
        // It checks if Dtd section is empty. 
        private bool _dtdStart = false;

        // The State represents a section, where the xmlwriter is situated. e.g. When you call startComment, the xmlwriter changes its state to Comment
        private enum State 
        {
            Comment, 
            PI, // Processing instruction
            CDATA, 
            DTD, 
            DtdElement, 
            DtdEntity, 
            DtdAttlist 
        }

        // There can be actually two levels, where the state of xmlwriter can be situated. You can move to DtdElement if you are in DTD and you can move to CDATA if you are in PI.
        Stack<State> _state = new Stack<State>(2);

        static XmlWriterSettings DefaultSettings = new XmlWriterSettings()
        {
            Encoding = new UTF8Encoding(false),     // Disable BOM
            Indent = false,
            NewLineChars = "\n",
            WriteEndDocumentOnClose = true,
            ConformanceLevel = ConformanceLevel.Auto
        };

        #endregion

        void IDisposable.Dispose()
        {
            _writer?.Dispose();
{'fraction_non_alphanumeric': 0.07038544409863538, 'fraction_numerical': 0.0023940627244433805, 'mean_word_length': 2.120238984316654, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '2126353', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1063, 'n_words': 388}