Permalink
Browse files

Start to move some method to an external IronRuby.Hpricot.Utilities c…

…lass.
  • Loading branch information...
1 parent 8265e8d commit 04c29c6c5c17ec8bcb9f50a91e190cb76d1e3050 @nrk committed Jul 17, 2010
Showing with 22 additions and 7 deletions.
  1. +7 −7 src/HpricotScanner.cs
  2. +1 −0 src/IronRuby.Hpricot.csproj
  3. +14 −0 src/Utilities.cs
View
@@ -1054,7 +1054,7 @@ public class HpricotScanner {
he.EC = ec;
if (raw > -1 && (sym_emptytag.Equals(sym) || sym_stag.Equals(sym) || sym_etag.Equals(sym) || sym_doctype.Equals(sym))) {
- he.Raw = MutableString.Create(new String(buf, raw, rawlen), RubyEncoding.Binary);
+ he.Raw = Utilities.CreateMutableStringFromBuffer(buf, raw, rawlen);
}
}
else if (ele is DocumentType || ele is ProcedureInstruction || ele is XmlDeclaration || ele is ETag || ele is BogusETag) {
@@ -1063,7 +1063,7 @@ public class HpricotScanner {
ha.Tag = tag;
if (ele is ETag || ele is BogusETag) {
if (raw > -1) {
- ha.Attr = MutableString.Create(new String(buf, raw, rawlen), RubyEncoding.Binary);
+ ha.Attr = Utilities.CreateMutableStringFromBuffer(buf, raw, rawlen);
}
}
else {
@@ -1136,7 +1136,7 @@ public class HpricotScanner {
(!sym_procins.Equals(sym) && !sym_comment.Equals(sym) && !sym_cdata.Equals(sym) && !sym_text.Equals(sym)) &&
!(sym_etag.Equals(sym) && tag.GetHashCode() == last.Name.GetHashCode())) {
sym = sym_text;
- tag = MutableString.Create(new String(buf, raw, rawlen), RubyEncoding.Binary);
+ tag = Utilities.CreateMutableStringFromBuffer(buf, raw, rawlen);
}
if (ec != null) {
@@ -1317,7 +1317,7 @@ public class HpricotScanner {
if (_blockParam != null) {
MutableString raw_string = null;
if (raw > 0) {
- raw_string = MutableString.Create(new String(buf, raw, rawlen), RubyEncoding.Binary);
+ raw_string = Utilities.CreateMutableStringFromBuffer(buf, raw, rawlen);
}
// NOTE: right before v0.7 the fourth argument of rb_yield_tokens was yielding raw_string
// but now it yields null (hardcoded). I still have to understand why, but this
@@ -1337,23 +1337,23 @@ public class HpricotScanner {
tag[0] = MutableString.CreateEmpty();
}
else if (E > mark_tag) {
- tag[0] = MutableString.Create(new String(buf, mark_tag, E - mark_tag), RubyEncoding.Binary);
+ tag[0] = Utilities.CreateMutableStringFromBuffer(buf, mark_tag, E - mark_tag);
}
}
else if (N == akey) {
if (mark_akey == -1 || E == mark_akey) {
akey[0] = MutableString.CreateEmpty();
}
else if (E > mark_akey) {
- akey[0] = MutableString.Create(new String(buf, mark_akey, E - mark_akey), RubyEncoding.Binary);
+ akey[0] = Utilities.CreateMutableStringFromBuffer(buf, mark_akey, E - mark_akey);
}
}
else if (N == aval) {
if (mark_aval == -1 || E == mark_aval) {
aval[0] = MutableString.CreateEmpty();
}
else if (E > mark_aval) {
- aval[0] = MutableString.Create(new String(buf, mark_aval, E - mark_aval), RubyEncoding.Binary);
+ aval[0] = Utilities.CreateMutableStringFromBuffer(buf, mark_aval, E - mark_aval);
}
}
}
@@ -84,6 +84,7 @@
<Compile Include="ScannerState.cs" />
<Compile Include="Initializers.Generated.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Utilities.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Ragel\HpricotScanner.common.rl" />
View
@@ -0,0 +1,14 @@
+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 MutableString CreateMutableStringFromBuffer(char[] buffer, int raw, int rawlen) {
+ return MutableString.Create(new String(buffer, raw, rawlen), RubyEncoding.Binary);
+ }
+ }
+}

0 comments on commit 04c29c6

Please sign in to comment.