Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change the constructor of every class that implements IHpricotDataCon…

…tainer.
  • Loading branch information...
commit f1807740c229677155f4e0fe995cbecf3ae40cd4 1 parent caf6151
@nrk authored
Showing with 100 additions and 51 deletions.
  1. +89 −39 src/Hpricot.cs
  2. +11 −12 src/HpricotScanner.cs
View
128 src/Hpricot.cs
@@ -63,11 +63,19 @@ public static class Hpricot {
[RubyClass("Doc")]
public class Document : IHpricotDataContainer {
+ private RubyContext _context;
private ElementData _data;
- public Document() : this(new ElementData()) { }
+ public Document(ScannerState state)
+ : this(state.Context) {
+ }
+
+ public Document(RubyContext context)
+ : this(context, new ElementData()) {
+ }
- public Document(ElementData data) {
+ public Document(RubyContext context, ElementData data) {
+ _context = context;
_data = data;
}
@@ -77,7 +85,7 @@ public class Document : IHpricotDataContainer {
[RubyConstructor]
public static Document Allocator(RubyClass/*!*/ self) {
- return new Document();
+ return new Document(self.Context);
}
[RubyMethod("children")]
@@ -97,8 +105,26 @@ public class Document : IHpricotDataContainer {
[RubyClass("BaseEle")]
public abstract class BaseElement : IHpricotDataContainer {
+ protected RubyContext _context;
protected BasicData _data;
+ public BaseElement(ScannerState state)
+ : this(state.Context, new BasicData()) {
+ }
+
+ public BaseElement(ScannerState state, BasicData data)
+ : this(state.Context, data) {
+ }
+
+ public BaseElement(RubyContext context)
+ : this(context, new BasicData()) {
+ }
+
+ public BaseElement(RubyContext context, BasicData data) {
+ _context = context;
+ _data = data;
+ }
+
public T GetData<T>() where T : BasicData {
return _data as T;
}
@@ -131,15 +157,17 @@ public abstract class BaseElement : IHpricotDataContainer {
[RubyClass("CData", Inherits = typeof(BaseElement))]
public class CData : BaseElement {
- public CData() : this(new BasicData()) { }
+ public CData(ScannerState state)
+ : this(state.Context) {
+ }
- public CData(BasicData data) {
- _data = data;
+ public CData(RubyContext context)
+ : base(context) {
}
[RubyConstructor]
public static CData Allocator(RubyClass/*!*/ self) {
- return new CData();
+ return new CData(self.Context);
}
protected override MutableString RawString {
@@ -165,15 +193,17 @@ public class CData : BaseElement {
[RubyClass("Comment", Inherits = typeof(BaseElement))]
public class Comment : BaseElement {
- public Comment() : this(new BasicData()) { }
+ public Comment(ScannerState state)
+ : this(state.Context) {
+ }
- public Comment(BasicData data) {
- _data = data;
+ public Comment(RubyContext context)
+ : base(context) {
}
[RubyConstructor]
public static Comment Allocator(RubyClass/*!*/ self) {
- return new Comment();
+ return new Comment(self.Context);
}
protected override MutableString RawString {
@@ -202,15 +232,17 @@ public class DocumentType : BaseElement {
private static readonly SymbolId _systemId = SymbolTable.StringToId("system_id");
private static readonly SymbolId _publicId = SymbolTable.StringToId("public_id");
- public DocumentType() : this(new AttributeData()) { }
+ public DocumentType(ScannerState state)
+ : this(state.Context) {
+ }
- public DocumentType(AttributeData data) {
- _data = data;
+ public DocumentType(RubyContext context)
+ : base(context, new AttributeData()) {
}
-
+
[RubyConstructor]
public static DocumentType Allocator(RubyClass/*!*/ self) {
- return new DocumentType();
+ return new DocumentType(self.Context);
}
protected override MutableString RawString {
@@ -293,15 +325,17 @@ public class DocumentType : BaseElement {
[RubyClass("Elem", Inherits = typeof(BaseElement))]
public class Element : BaseElement {
- public Element() : this(new ElementData()) { }
+ public Element(ScannerState state)
+ : this(state.Context) {
+ }
- public Element(ElementData data) {
- _data = data;
+ public Element(RubyContext context)
+ : base(context, new ElementData()) {
}
[RubyConstructor]
public static Element Allocator(RubyClass/*!*/ self) {
- return new Element();
+ return new Element(self.Context);
}
[RubyMethod("raw_string")]
@@ -362,15 +396,17 @@ public class Element : BaseElement {
[RubyClass("ETag", Inherits = typeof(BaseElement))]
public class ETag : BaseElement {
- public ETag() : this(new AttributeData()) { }
+ public ETag(ScannerState state)
+ : this(state.Context) {
+ }
- public ETag(AttributeData data) {
- _data = data;
+ public ETag(RubyContext context)
+ : base(context, new AttributeData()) {
}
[RubyConstructor]
public static ETag Allocator(RubyClass/*!*/ self) {
- return new ETag();
+ return new ETag(self.Context);
}
[RubyMethod("raw_string")]
@@ -403,9 +439,17 @@ public class ETag : BaseElement {
[RubyClass("BogusETag", Inherits = typeof(ETag))]
public class BogusETag : ETag {
+ public BogusETag(ScannerState state)
+ : this(state.Context) {
+ }
+
+ public BogusETag(RubyContext context)
+ : base(context) {
+ }
+
[RubyConstructor]
public static new BogusETag Allocator(RubyClass/*!*/ self) {
- return new BogusETag();
+ return new BogusETag(self.Context);
}
}
@@ -414,16 +458,18 @@ public class BogusETag : ETag {
#region Hpricot::Text
[RubyClass("Text", Inherits = typeof(BaseElement))]
- public class Text : BaseElement {
- public Text() : this(new BasicData()) { }
+ public class Text : BaseElement {
+ public Text(ScannerState state)
+ : this(state.Context) {
+ }
- public Text(BasicData data) {
- _data = data;
+ public Text(RubyContext context)
+ : base(context) {
}
[RubyConstructor]
public static Text Allocator(RubyClass/*!*/ self) {
- return new Text();
+ return new Text(self.Context);
}
[RubyMethod("content")]
@@ -447,15 +493,17 @@ public class XmlDeclaration : BaseElement {
private static readonly SymbolId _standalone = SymbolTable.StringToId("standalone");
private static readonly SymbolId _version = SymbolTable.StringToId("version");
- public XmlDeclaration() : this(new AttributeData()) { }
+ public XmlDeclaration(ScannerState state)
+ : this(state.Context) {
+ }
- public XmlDeclaration(AttributeData data) {
- _data = data;
+ public XmlDeclaration(RubyContext context)
+ : base(context, new AttributeData()) {
}
[RubyConstructor]
public static XmlDeclaration Allocator(RubyClass/*!*/ self) {
- return new XmlDeclaration();
+ return new XmlDeclaration(self.Context);
}
protected override MutableString RawString {
@@ -551,15 +599,17 @@ public class XmlDeclaration : BaseElement {
[RubyClass("ProcIns", Inherits = typeof(BaseElement))]
public class ProcedureInstruction : BaseElement {
- public ProcedureInstruction() : this(new AttributeData()) { }
-
- public ProcedureInstruction(AttributeData data) {
- _data = data;
+ public ProcedureInstruction(ScannerState state)
+ : this(state.Context) {
}
+ public ProcedureInstruction(RubyContext context)
+ : base(context, new AttributeData()) {
+ }
+
[RubyConstructor]
public static ProcedureInstruction Allocator(RubyClass/*!*/ self) {
- return new ProcedureInstruction();
+ return new ProcedureInstruction(self.Context);
}
protected override MutableString RawString {
View
23 src/HpricotScanner.cs
@@ -1171,7 +1171,7 @@ public class HpricotScanner {
}
if (sym_emptytag.Equals(sym) || sym_stag.Equals(sym)) {
- var ele = H_ELE(new Hpricot.Element(), state, sym, tag, attr, ec, raw, rawlen);
+ var ele = H_ELE(new Hpricot.Element(state), state, sym, tag, attr, ec, raw, rawlen);
var he = ele.GetData<ElementData>();
he.Name = tag.GetHashCode();
@@ -1259,10 +1259,10 @@ public class HpricotScanner {
}
if (match == null) {
- rb_hpricot_add(state.Focus, H_ELE(new Hpricot.BogusETag(), state, sym, tag, attr, ec, raw, rawlen));
+ rb_hpricot_add(state.Focus, H_ELE(new Hpricot.BogusETag(state), state, sym, tag, attr, ec, raw, rawlen));
}
else {
- var ele = H_ELE(new Hpricot.ETag(), state, sym, tag, attr, ec, raw, rawlen);
+ var ele = H_ELE(new Hpricot.ETag(state), state, sym, tag, attr, ec, raw, rawlen);
Debug.Assert(match is IHpricotDataContainer, "match is not an instance of IHpricotDataContainer");
ElementData he = (match as Hpricot.Element).GetData<ElementData>();
@@ -1277,10 +1277,10 @@ public class HpricotScanner {
}
else if (sym_cdata.Equals(sym)) {
- rb_hpricot_add(state.Focus, H_ELE(new Hpricot.CData(), state, sym, tag, attr, ec, raw, rawlen));
+ rb_hpricot_add(state.Focus, H_ELE(new Hpricot.CData(state), state, sym, tag, attr, ec, raw, rawlen));
}
else if (sym_comment.Equals(sym)) {
- rb_hpricot_add(state.Focus, H_ELE(new Hpricot.Comment(), state, sym, tag, attr, ec, raw, rawlen));
+ rb_hpricot_add(state.Focus, H_ELE(new Hpricot.Comment(state), state, sym, tag, attr, ec, raw, rawlen));
}
else if (sym_doctype.Equals(sym)) {
if (state.Strict) {
@@ -1289,7 +1289,7 @@ public class HpricotScanner {
(attr as Hash).Add(SymbolTable.StringToId("system_id"), MutableString.CreateAscii("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"));
(attr as Hash).Add(SymbolTable.StringToId("public_id"), MutableString.CreateAscii("-//W3C//DTD XHTML 1.0 Strict//EN"));
}
- rb_hpricot_add(state.Focus, H_ELE(new Hpricot.DocumentType(), state, sym, tag, attr, ec, raw, rawlen));
+ rb_hpricot_add(state.Focus, H_ELE(new Hpricot.DocumentType(state), state, sym, tag, attr, ec, raw, rawlen));
}
else if (sym_procins.Equals(sym)) {
Debug.Assert(tag is MutableString, "tag is not an instance of MutableString");
@@ -1299,7 +1299,7 @@ public class HpricotScanner {
tag = match.GetGroupValue(1);
attr = match.GetGroupValue(2);
- rb_hpricot_add(state.Focus, H_ELE(new Hpricot.ProcedureInstruction(), state, sym, tag, attr, ec, raw, rawlen));
+ rb_hpricot_add(state.Focus, H_ELE(new Hpricot.ProcedureInstruction(state), state, sym, tag, attr, ec, raw, rawlen));
}
else if (sym_text.Equals(sym)) {
// TODO: add raw_string as well?
@@ -1312,11 +1312,11 @@ public class HpricotScanner {
(he.Tag as MutableString).Append(tag as MutableString);
}
else {
- rb_hpricot_add(state.Focus, H_ELE(new Hpricot.Text(), state, sym, tag, attr, ec, raw, rawlen));
+ rb_hpricot_add(state.Focus, H_ELE(new Hpricot.Text(state), state, sym, tag, attr, ec, raw, rawlen));
}
}
else if (sym_xmldecl.Equals(sym)) {
- rb_hpricot_add(state.Focus, H_ELE(new Hpricot.XmlDeclaration(), state, sym, tag, attr, ec, raw, rawlen));
+ rb_hpricot_add(state.Focus, H_ELE(new Hpricot.XmlDeclaration(state), state, sym, tag, attr, ec, raw, rawlen));
}
}
@@ -1491,9 +1491,8 @@ public class HpricotScanner {
}
if (_blockParam == null) {
- ScannerState state = new ScannerState(_currentContext);
- Hpricot.Document doc = new Hpricot.Document();
- state.Doc = doc;
+ var state = new ScannerState(_currentContext);
+ state.Doc = new Hpricot.Document(state);
state.Focus = state.Doc as IHpricotDataContainer;
state.Xml = OPT(options, _optXml);
state.Strict = OPT(options, _optXhtmlStrict);
Please sign in to comment.
Something went wrong with that request. Please try again.