Skip to content

Commit

Permalink
Fix warnings from Resharper
Browse files Browse the repository at this point in the history
  • Loading branch information
Knagis committed May 2, 2015
1 parent 6f33fec commit abf31ed
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 275 deletions.
12 changes: 6 additions & 6 deletions CommonMark/CommonMarkConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static Version AssemblyVersion
public static Syntax.Block ProcessStage1(TextReader source, CommonMarkSettings settings = null)
{
if (source == null)
throw new ArgumentNullException("source");
throw new ArgumentNullException(nameof(source));

if (settings == null)
settings = CommonMarkSettings.Default;
Expand Down Expand Up @@ -166,10 +166,10 @@ public static Syntax.Block ProcessStage1(TextReader source, CommonMarkSettings s
public static void ProcessStage2(Syntax.Block document, CommonMarkSettings settings = null)
{
if (document == null)
throw new ArgumentNullException("document");
throw new ArgumentNullException(nameof(document));

if (document.Tag != Syntax.BlockTag.Document)
throw new ArgumentException("The block element passed to this method must represent a top level document.", "document");
throw new ArgumentException("The block element passed to this method must represent a top level document.", nameof(document));

if (settings == null)
settings = CommonMarkSettings.Default;
Expand Down Expand Up @@ -202,13 +202,13 @@ public static void ProcessStage2(Syntax.Block document, CommonMarkSettings setti
public static void ProcessStage3(Syntax.Block document, TextWriter target, CommonMarkSettings settings = null)
{
if (document == null)
throw new ArgumentNullException("document");
throw new ArgumentNullException(nameof(document));

if (target == null)
throw new ArgumentNullException("target");
throw new ArgumentNullException(nameof(target));

if (document.Tag != Syntax.BlockTag.Document)
throw new ArgumentException("The block element passed to this method must represent a top level document.", "document");
throw new ArgumentException("The block element passed to this method must represent a top level document.", nameof(document));

if (settings == null)
settings = CommonMarkSettings.Default;
Expand Down
271 changes: 135 additions & 136 deletions CommonMark/Formatters/HtmlFormatter.cs

Large diffs are not rendered by default.

45 changes: 23 additions & 22 deletions CommonMark/Formatters/HtmlFormatterSlim.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
using CommonMark.Syntax;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using CommonMark.Syntax;

namespace CommonMark.Formatters
{
internal static class HtmlFormatterSlim
{
private static readonly char[] EscapeHtmlCharacters = new[] { '&', '<', '>', '"' };
private static readonly char[] EscapeHtmlCharacters = { '&', '<', '>', '"' };
private const string HexCharacters = "0123456789ABCDEF";

private static readonly char[] EscapeHtmlLessThan = "&lt;".ToCharArray();
private static readonly char[] EscapeHtmlGreaterThan = "&gt;".ToCharArray();
private static readonly char[] EscapeHtmlAmpersand = "&amp;".ToCharArray();
private static readonly char[] EscapeHtmlQuote = "&quot;".ToCharArray();

private static readonly string[] HeaderOpenerTags = new[] { "<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>" };
private static readonly string[] HeaderCloserTags = new[] { "</h1>", "</h2>", "</h3>", "</h4>", "</h5>", "</h6>" };
private static readonly string[] HeaderOpenerTags = { "<h1>", "<h2>", "<h3>", "<h4>", "<h5>", "<h6>" };
private static readonly string[] HeaderCloserTags = { "</h1>", "</h2>", "</h3>", "</h4>", "</h5>", "</h6>" };

private static readonly bool[] UrlSafeCharacters = new[] {
private static readonly bool[] UrlSafeCharacters = {
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
false, true, false, true, true, true, false, false, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, true, false, true, false, true,
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, true,
false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false,
true, true, true, true, true, true, true, true, true, true, true, false, false, false, false, false
};

/// <summary>
Expand Down Expand Up @@ -160,7 +161,7 @@ internal static void EscapeHtml(StringContent inp, HtmlTextWriter target)

part.Source.CopyTo(part.StartIndex, buffer, 0, part.Length);

lastPos = pos = part.StartIndex;
lastPos = part.StartIndex;
while ((pos = part.Source.IndexOfAny(EscapeHtmlCharacters, lastPos, part.Length - lastPos + part.StartIndex)) != -1)
{
target.Write(buffer, lastPos - part.StartIndex, pos - lastPos);
Expand All @@ -187,7 +188,7 @@ internal static void EscapeHtml(StringContent inp, HtmlTextWriter target)
}
}

public static void BlocksToHtml(System.IO.TextWriter writer, Block block, CommonMarkSettings settings)
public static void BlocksToHtml(TextWriter writer, Block block, CommonMarkSettings settings)
{
var wrapper = new HtmlTextWriter(writer);
BlocksToHtmlInner(wrapper, block, settings);
Expand All @@ -196,18 +197,18 @@ public static void BlocksToHtml(System.IO.TextWriter writer, Block block, Common
internal static void PrintPosition(HtmlTextWriter writer, Block block)
{
writer.WriteConstant(" data-sourcepos=\"");
writer.WriteConstant(block.SourcePosition.ToString(System.Globalization.CultureInfo.InvariantCulture));
writer.WriteConstant(block.SourcePosition.ToString(CultureInfo.InvariantCulture));
writer.Write('-');
writer.WriteConstant(block.SourceLastPosition.ToString(System.Globalization.CultureInfo.InvariantCulture));
writer.WriteConstant(block.SourceLastPosition.ToString(CultureInfo.InvariantCulture));
writer.WriteConstant("\"");
}

internal static void PrintPosition(HtmlTextWriter writer, Inline inline)
{
writer.WriteConstant(" data-sourcepos=\"");
writer.WriteConstant(inline.SourcePosition.ToString(System.Globalization.CultureInfo.InvariantCulture));
writer.WriteConstant(inline.SourcePosition.ToString(CultureInfo.InvariantCulture));
writer.Write('-');
writer.WriteConstant(inline.SourceLastPosition.ToString(System.Globalization.CultureInfo.InvariantCulture));
writer.WriteConstant(inline.SourceLastPosition.ToString(CultureInfo.InvariantCulture));
writer.WriteConstant("\"");
}

Expand Down Expand Up @@ -280,7 +281,7 @@ private static void BlocksToHtmlInner(HtmlTextWriter writer, Block block, Common
if (data.Start != 1)
{
writer.WriteConstant(" start=\"");
writer.WriteConstant(data.Start.ToString(System.Globalization.CultureInfo.InvariantCulture));
writer.WriteConstant(data.Start.ToString(CultureInfo.InvariantCulture));
writer.Write('\"');
}
if (trackPositions) PrintPosition(writer, block);
Expand Down Expand Up @@ -425,7 +426,7 @@ private static void InlinesToPlainText(HtmlTextWriter writer, Inline inline, Sta
writer.Write('[');
stackLiteral = "]";
visitChildren = true;
stackWithinLink = withinLink;
stackWithinLink = true;
}
else
{
Expand Down Expand Up @@ -542,7 +543,7 @@ private static void InlinesToHtml(HtmlTextWriter writer, Inline inline, CommonMa
{
writer.Write('[');
stackLiteral = "]";
stackWithinLink = withinLink;
stackWithinLink = true;
visitChildren = true;
}
else
Expand Down Expand Up @@ -657,9 +658,9 @@ private struct BlockStackEntry
public readonly bool IsTight;
public BlockStackEntry(string literal, Block target, bool isTight)
{
this.Literal = literal;
this.Target = target;
this.IsTight = isTight;
Literal = literal;
Target = target;
IsTight = isTight;
}
}
private struct InlineStackEntry
Expand All @@ -669,9 +670,9 @@ private struct InlineStackEntry
public readonly bool IsWithinLink;
public InlineStackEntry(string literal, Inline target, bool isWithinLink)
{
this.Literal = literal;
this.Target = target;
this.IsWithinLink = isWithinLink;
Literal = literal;
Target = target;
IsWithinLink = isWithinLink;
}
}
}
Expand Down
23 changes: 10 additions & 13 deletions CommonMark/Formatters/HtmlTextWriter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using CommonMark.Syntax;

namespace CommonMark.Formatters
{
Expand All @@ -9,18 +8,18 @@ namespace CommonMark.Formatters
/// </summary>
internal sealed class HtmlTextWriter
{
private System.IO.TextWriter _inner;
private readonly TextWriter _inner;
private char _last = '\n';
private bool _windowsNewLine;
private char[] _newline;
private readonly bool _windowsNewLine;
private readonly char[] _newline;

/// <summary>
/// A reusable char buffer. This is used internally in <see cref="Write(Syntax.StringPart)"/> (and thus will modify the buffer)
/// but can also be used from <see cref="HtmlFormatterSlim"/> class.
/// </summary>
internal char[] Buffer = new char[256];

public HtmlTextWriter(System.IO.TextWriter inner)
public HtmlTextWriter(TextWriter inner)
{
this._inner = inner;

Expand All @@ -45,7 +44,7 @@ public void WriteLine(char data)
this._last = '\n';
}

public void Write(Syntax.StringPart value)
public void Write(StringPart value)
{
if (value.Length == 0)
return;
Expand All @@ -59,11 +58,10 @@ public void Write(Syntax.StringPart value)
{
var lastPos = value.StartIndex;
var pos = lastPos;
var lastC = this._last;

while (-1 != (pos = value.Source.IndexOf('\n', pos, value.Length - pos + value.StartIndex)))
{
lastC = pos == 0 ? this._last : value.Source[pos - 1];
var lastC = pos == 0 ? this._last : value.Source[pos - 1];

if (lastC != '\r')
{
Expand Down Expand Up @@ -130,8 +128,7 @@ public void Write(char[] value, int index, int count)
if (this._windowsNewLine)
{
var lastPos = index;
var lastC = this._last;
int pos = index;
var pos = index;

while (pos < index + count)
{
Expand All @@ -141,7 +138,7 @@ public void Write(char[] value, int index, int count)
continue;
}

lastC = pos == index ? this._last : value[pos - 1];
var lastC = pos == index ? this._last : value[pos - 1];

if (lastC != '\r')
{
Expand Down
14 changes: 7 additions & 7 deletions CommonMark/Formatters/Printer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommonMark.Syntax;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Text;
using CommonMark.Syntax;

namespace CommonMark.Formatters
{
Expand Down Expand Up @@ -45,7 +45,7 @@ private static string format_str(string s, StringBuilder buffer)
#if OptimizeFor45
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
#endif
private static void PrintPosition(bool enabled, System.IO.TextWriter writer, Block block)
private static void PrintPosition(bool enabled, TextWriter writer, Block block)
{
if (enabled)
{
Expand All @@ -60,7 +60,7 @@ private static void PrintPosition(bool enabled, System.IO.TextWriter writer, Blo
#if OptimizeFor45
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
#endif
private static void PrintPosition(bool enabled, System.IO.TextWriter writer, Inline inline)
private static void PrintPosition(bool enabled, TextWriter writer, Inline inline)
{
if (enabled)
{
Expand All @@ -75,7 +75,7 @@ private static void PrintPosition(bool enabled, System.IO.TextWriter writer, Inl
/// <summary>
/// Write the block data to the given writer.
/// </summary>
public static void PrintBlocks(System.IO.TextWriter writer, Block block, CommonMarkSettings settings)
public static void PrintBlocks(TextWriter writer, Block block, CommonMarkSettings settings)
{
int indent = 0;
var stack = new Stack<BlockStackEntry>();
Expand Down Expand Up @@ -210,7 +210,7 @@ public static void PrintBlocks(System.IO.TextWriter writer, Block block, CommonM
}
}

private static void PrintInlines(System.IO.TextWriter writer, Inline inline, int indent, Stack<InlineStackEntry> stack, StringBuilder buffer, bool trackPositions)
private static void PrintInlines(TextWriter writer, Inline inline, int indent, Stack<InlineStackEntry> stack, StringBuilder buffer, bool trackPositions)
{
while (inline != null)
{
Expand Down
26 changes: 12 additions & 14 deletions CommonMark/Parser/BlockMethods.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CommonMark.Syntax;
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Generic;
using System.Globalization;
using CommonMark.Syntax;

namespace CommonMark.Parser
{
Expand Down Expand Up @@ -34,7 +33,7 @@ private static bool AcceptsLines(BlockTag block_type)
private static void AddLine(Block block, LineInfo lineInfo, string ln, int offset, int length = -1)
{
if (!block.IsOpen)
throw new CommonMarkException(string.Format(System.Globalization.CultureInfo.InvariantCulture, "Attempted to add line '{0}' to closed container ({1}).", ln, block.Tag));
throw new CommonMarkException(string.Format(CultureInfo.InvariantCulture, "Attempted to add line '{0}' to closed container ({1}).", ln, block.Tag));

var len = length == -1 ? ln.Length - offset : length;
if (len <= 0)
Expand Down Expand Up @@ -399,12 +398,12 @@ private static bool ContainsSingleLine(StringContent content)
return (i == -1 || i == content.Length - 1);
}

private static bool ListsMatch(ListData list_data, ListData item_data)
private static bool ListsMatch(ListData listData, ListData itemData)
{
return (list_data.ListType == item_data.ListType &&
list_data.Delimiter == item_data.Delimiter &&
return (listData.ListType == itemData.ListType &&
listData.Delimiter == itemData.Delimiter &&
// list_data.marker_offset == item_data.marker_offset &&
list_data.BulletChar == item_data.BulletChar);
listData.BulletChar == itemData.BulletChar);
}

// Process one line at a time, modifying a block.
Expand All @@ -415,20 +414,19 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
var ln = line.Line;

Block last_matched_container;
int offset = 0;
int matched = 0;
var offset = 0;
int matched;
int i;
ListData data;
bool all_matched = true;
Block container;
Block cur = curptr;
bool blank = false;
int first_nonspace;
char curChar;
int indent;

// container starts at the document root.
container = cur.Top;
var container = cur.Top;

// for each containing block, try to parse the associated line start.
// bail out on failure: container will point to the last matching block.
Expand Down Expand Up @@ -632,7 +630,7 @@ public static void IncorporateLine(LineInfo line, ref Block curptr)
offset = ln.Length - 1;

}
else if (!(container.Tag == BlockTag.Paragraph && !all_matched) && 0 != (matched = Scanner.scan_hrule(ln, first_nonspace, ln.Length)))
else if (!(container.Tag == BlockTag.Paragraph && !all_matched) && 0 != (Scanner.scan_hrule(ln, first_nonspace, ln.Length)))
{

// it's only now that we know the line is not part of a setext header:
Expand Down
Loading

0 comments on commit abf31ed

Please sign in to comment.