Skip to content

Commit

Permalink
Merge pull request #534 from Shane32/refactor_ext_methods
Browse files Browse the repository at this point in the history
Refactor compatibility extension methods
  • Loading branch information
codebude authored May 24, 2024
2 parents 923dbe5 + d5e466d commit 6b7311b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QRCoder.Framework4._0Methods
#if NET35
namespace QRCoder
{
class Stream4Methods
internal static class StreamExtensions
{
public static void CopyTo(System.IO.Stream input, System.IO.Stream output)
/// <summary>
/// Copies a stream to another stream.
/// </summary>
public static void CopyTo(this System.IO.Stream input, System.IO.Stream output)
{
byte[] buffer = new byte[16 * 1024];
int bytesRead;
Expand All @@ -18,3 +17,4 @@ public static void CopyTo(System.IO.Stream input, System.IO.Stream output)
}
}
}
#endif
27 changes: 27 additions & 0 deletions QRCoder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace QRCoder
{
internal static class StringExtensions
{
/// <summary>
/// Indicates whether the specified string is null, empty, or consists only of white-space characters.
/// </summary>
/// <returns>
/// <see langword="true"/> if the <paramref name="value"/> is null, empty, or white space; otherwise, <see langword="false"/>.
/// </returns>
public static bool IsNullOrWhiteSpace(this string value)
{
#if NET35
if (value == null) return true;

for (int i = 0; i < value.Length; i++)
{
if (!char.IsWhiteSpace(value[i])) return false;
}

return true;
#else
return string.IsNullOrWhiteSpace(value);
#endif
}
}
}
48 changes: 0 additions & 48 deletions QRCoder/Framework4.0Methods/String4Methods.cs

This file was deleted.

6 changes: 3 additions & 3 deletions QRCoder/PayloadGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ private string TimeToString()

private void ProcessCommonFields(StringBuilder sb)
{
if (String40Methods.IsNullOrWhiteSpace(Secret))
if (Secret.IsNullOrWhiteSpace())
{
throw new Exception("Secret must be a filled out base32 encoded string");
}
Expand All @@ -2043,7 +2043,7 @@ private void ProcessCommonFields(StringBuilder sb)
string escapedLabel = null;
string label = null;

if (!String40Methods.IsNullOrWhiteSpace(Issuer))
if (!Issuer.IsNullOrWhiteSpace())
{
if (Issuer.Contains(":"))
{
Expand All @@ -2052,7 +2052,7 @@ private void ProcessCommonFields(StringBuilder sb)
escapedIssuer = Uri.EscapeDataString(Issuer);
}

if (!String40Methods.IsNullOrWhiteSpace(Label))
if (!Label.IsNullOrWhiteSpace())
{
if (Label.Contains(":"))
{
Expand Down
13 changes: 5 additions & 8 deletions QRCoder/QRCodeData.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.IO.Compression;

namespace QRCoder
{
using QRCoder.Framework4._0Methods;
using System;
using System.IO;
using System.IO.Compression;

public class QRCodeData : IDisposable
{
public List<BitArray> ModuleMatrix { get; set; }
Expand Down Expand Up @@ -48,7 +45,7 @@ public QRCodeData(byte[] rawData, Compression compressMode)
{
using (var dstream = new DeflateStream(input, CompressionMode.Decompress))
{
Stream4Methods.CopyTo(dstream, output);
dstream.CopyTo(output);
}
bytes = new List<byte>(output.ToArray());
}
Expand All @@ -62,7 +59,7 @@ public QRCodeData(byte[] rawData, Compression compressMode)
{
using (var dstream = new GZipStream(input, CompressionMode.Decompress))
{
Stream4Methods.CopyTo(dstream, output);
dstream.CopyTo(output);
}
bytes = new List<byte>(output.ToArray());
}
Expand Down

0 comments on commit 6b7311b

Please sign in to comment.