<commit_before>﻿using System;
using System.Text;
using IronRuby.Builtins;
using IronRuby.Runtime;
using Microsoft.Scripting;
using Microsoft.Scripting.Runtime;

namespace IronRuby.Hpricot {
    public static class Utilities {
        public static readonly RubyRegex ProcessInstructionParser = new RubyRegex(MutableString.CreateAscii(@"\A<\?(\S+)\s+(.+)"), RubyRegexOptions.Multiline);

        public static MutableString CreateMutableStringFromBuffer(char[] buffer, int raw, int rawlen) { 
            return MutableString.Create(new String(buffer, raw, rawlen), RubyEncoding.Binary);
        }

        public static RubyModule GetHpricotModule(RubyContext context) {
            RubyModule hpricotModule;
            if (!context.TryGetModule(typeof(Hpricot), out hpricotModule)) {
                RubyExceptions.CreateNameError("Cannot find module Hpricot");
            }
            return hpricotModule;
        }

        public static Int32? GetBufferSize(RubyContext context) {
            return GetBufferSize(GetHpricotModule(context));
        }

        public static Int32? GetBufferSize(RubyModule hpricotModule) {
            Object bufferSize;
            if (hpricotModule.TryGetClassVariable("@@buffer_size", out bufferSize)) {
                return (int)bufferSize;
            }
            return null;
        }

        public static void SetBufferSize(RubyContext context, Int32 bufferSize) {
            SetBufferSize(GetHpricotModule(context), bufferSize);
        }
<commit_msg>Change the way MutableString instances are created from the buffer.<commit_after>﻿using System;
using System.Text;
using IronRuby.Builtins;
using IronRuby.Runtime;
using Microsoft.Scripting;
using Microsoft.Scripting.Runtime;

namespace IronRuby.Hpricot {
    public static class Utilities {
        public static readonly RubyRegex ProcessInstructionParser = new RubyRegex(MutableString.CreateAscii(@"\A<\?(\S+)\s+(.+)"), RubyRegexOptions.Multiline);

        public static MutableString CreateMutableStringFromBuffer(char[] buffer, int raw, int rawlen) { 
            return MutableString.CreateMutable(rawlen, RubyEncoding.Binary).Append(buffer, raw, rawlen);
        }

        public static RubyModule GetHpricotModule(RubyContext context) {
            RubyModule hpricotModule;
            if (!context.TryGetModule(typeof(Hpricot), out hpricotModule)) {
                RubyExceptions.CreateNameError("Cannot find module Hpricot");
            }
            return hpricotModule;
        }

        public static Int32? GetBufferSize(RubyContext context) {
            return GetBufferSize(GetHpricotModule(context));
        }

        public static Int32? GetBufferSize(RubyModule hpricotModule) {
            Object bufferSize;
            if (hpricotModule.TryGetClassVariable("@@buffer_size", out bufferSize)) {
                return (int)bufferSize;
            }
            return null;
        }

        public static void SetBufferSize(RubyContext context, Int32 bufferSize) {
            SetBufferSize(GetHpricotModule(context), bufferSize);
        }

{'fraction_non_alphanumeric': 0.08436080467229072, 'fraction_numerical': 0.003893575600259572, 'mean_word_length': 2.917407878017789, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6564975', 'n_tokens_mistral': 866, 'n_tokens_neox': 784, 'n_words': 186}