Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (37 sloc) 1.68 KB
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);
}
public static void SetBufferSize(RubyModule hpricotModule, Int32 bufferSize) {
hpricotModule.SetClassVariable("@@buffer_size", bufferSize);
}
}
}