Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…lass.
  • Loading branch information...
commit 04c29c6c5c17ec8bcb9f50a91e190cb76d1e3050 1 parent 8265e8d
@nrk authored
View
14 src/HpricotScanner.cs
@@ -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,7 +1337,7 @@ 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) {
@@ -1345,7 +1345,7 @@ public class HpricotScanner {
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) {
@@ -1353,7 +1353,7 @@ public class HpricotScanner {
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);
}
}
}
View
1  src/IronRuby.Hpricot.csproj
@@ -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
14 src/Utilities.cs
@@ -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);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.