Browse Source

Making all number parsing invariant

Fixes #38, fixes #39


Former-commit-id: 0a88398bb4920fd6ec2ed742fac7b05889dde112
pull/17/head
James South 12 years ago
parent
commit
32a3f698c4
  1. 14
      src/ImageProcessor/Extensions/IntegerExtensions.cs
  2. 4
      src/ImageProcessor/Extensions/StringExtensions.cs
  3. 3
      src/ImageProcessor/Processors/Alpha.cs
  4. 3
      src/ImageProcessor/Processors/Brightness.cs
  5. 3
      src/ImageProcessor/Processors/Contrast.cs
  6. 7
      src/ImageProcessor/Processors/GaussianBlur.cs
  7. 7
      src/ImageProcessor/Processors/GaussianSharpen.cs
  8. 3
      src/ImageProcessor/Processors/Quality.cs
  9. 5
      src/ImageProcessor/Processors/Resize.cs
  10. 5
      src/ImageProcessor/Processors/Rotate.cs
  11. 5
      src/ImageProcessor/Processors/RoundedCorners.cs
  12. 3
      src/ImageProcessor/Processors/Saturation.cs
  13. 5
      src/ImageProcessor/Processors/Watermark.cs

14
src/ImageProcessor/Extensions/IntegerExtensions.cs

@ -10,6 +10,8 @@
namespace ImageProcessor.Extensions
{
using System.Globalization;
/// <summary>
/// Encapsulates a series of time saving extension methods to the <see cref="T:System.Int32"/> class.
/// </summary>
@ -32,5 +34,17 @@ namespace ImageProcessor.Extensions
{
return ((double)integer).ToByte();
}
/// <summary>
/// Converts the string representation of a number in a specified culture-specific format to its
/// 32-bit signed integer equivalent using invariant culture.
/// </summary>
/// <param name="integer">The integer.</param>
/// <param name="s">A string containing a number to convert.</param>
/// <returns>A 32-bit signed integer equivalent to the number specified in s.</returns>
public static int ParseInvariant(this int integer, string s)
{
return int.Parse(s, CultureInfo.InvariantCulture);
}
}
}

4
src/ImageProcessor/Extensions/StringExtensions.cs

@ -134,7 +134,7 @@ namespace ImageProcessor.Extensions
// Loop and parse the int values.
for (int i = 0; i < count; i++)
{
matches[i] = int.Parse(matchCollection[i].Value);
matches[i] = int.Parse(matchCollection[i].Value, CultureInfo.InvariantCulture);
}
return matches;
@ -163,7 +163,7 @@ namespace ImageProcessor.Extensions
// Loop and parse the int values.
for (int i = 0; i < count; i++)
{
matches[i] = float.Parse(matchCollection[i].Value);
matches[i] = float.Parse(matchCollection[i].Value, CultureInfo.InvariantCulture);
}
return matches;

3
src/ImageProcessor/Processors/Alpha.cs

@ -14,6 +14,7 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
@ -91,7 +92,7 @@ namespace ImageProcessor.Processors
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
int percentage = int.Parse(match.Value.Split('=')[1]);
int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}

3
src/ImageProcessor/Processors/Brightness.cs

@ -14,6 +14,7 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
@ -91,7 +92,7 @@ namespace ImageProcessor.Processors
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
int percentage = int.Parse(match.Value.Split('=')[1]);
int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}

3
src/ImageProcessor/Processors/Contrast.cs

@ -14,6 +14,7 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
@ -91,7 +92,7 @@ namespace ImageProcessor.Processors
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
int percentage = int.Parse(match.Value.Split('=')[1]);
int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}

7
src/ImageProcessor/Processors/GaussianBlur.cs

@ -13,6 +13,7 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Text.RegularExpressions;
using ImageProcessor.Imaging;
@ -98,9 +99,9 @@ namespace ImageProcessor.Processors
double maxSigma;
int maxThreshold;
int.TryParse(this.Settings["MaxSize"], out maxSize);
double.TryParse(this.Settings["MaxSigma"], out maxSigma);
int.TryParse(this.Settings["MaxThreshold"], out maxThreshold);
int.TryParse(this.Settings["MaxSize"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxSize);
double.TryParse(this.Settings["MaxSigma"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxSigma);
int.TryParse(this.Settings["MaxThreshold"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxThreshold);
int size = this.ParseBlur(match.Value);
double sigma = this.ParseSigma(match.Value);

7
src/ImageProcessor/Processors/GaussianSharpen.cs

@ -13,6 +13,7 @@ namespace ImageProcessor.Processors
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Text.RegularExpressions;
using ImageProcessor.Imaging;
@ -98,9 +99,9 @@ namespace ImageProcessor.Processors
double maxSigma;
int maxThreshold;
int.TryParse(this.Settings["MaxSize"], out maxSize);
double.TryParse(this.Settings["MaxSigma"], out maxSigma);
int.TryParse(this.Settings["MaxThreshold"], out maxThreshold);
int.TryParse(this.Settings["MaxSize"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxSize);
double.TryParse(this.Settings["MaxSigma"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxSigma);
int.TryParse(this.Settings["MaxThreshold"], NumberStyles.Any, CultureInfo.InvariantCulture, out maxThreshold);
int size = this.ParseSharpen(match.Value);
double sigma = this.ParseSigma(match.Value);

3
src/ImageProcessor/Processors/Quality.cs

@ -13,6 +13,7 @@ namespace ImageProcessor.Processors
#region Using
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
@ -89,7 +90,7 @@ namespace ImageProcessor.Processors
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
int percentage = int.Parse(match.Value.Split('=')[1]);
int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}

5
src/ImageProcessor/Processors/Resize.cs

@ -16,6 +16,7 @@ namespace ImageProcessor.Processors
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
@ -179,8 +180,8 @@ namespace ImageProcessor.Processors
int defaultMaxHeight;
string restrictions;
this.Settings.TryGetValue("RestrictTo", out restrictions);
int.TryParse(this.Settings["MaxWidth"], out defaultMaxWidth);
int.TryParse(this.Settings["MaxHeight"], out defaultMaxHeight);
int.TryParse(this.Settings["MaxWidth"], NumberStyles.Any, CultureInfo.InvariantCulture, out defaultMaxWidth);
int.TryParse(this.Settings["MaxHeight"], NumberStyles.Any, CultureInfo.InvariantCulture, out defaultMaxHeight);
List<Size> restrictedSizes = this.ParseRestrictions(restrictions);
return this.ResizeImage(factory, width, height, defaultMaxWidth, defaultMaxHeight, restrictedSizes, backgroundColor, mode, anchor, upscale, centerCoordinates);

5
src/ImageProcessor/Processors/Rotate.cs

@ -15,6 +15,7 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Text.RegularExpressions;
using ImageProcessor.Imaging;
#endregion
@ -114,7 +115,7 @@ namespace ImageProcessor.Processors
else
{
int degrees;
int.TryParse(match.Value.Split('=')[1], out degrees);
int.TryParse(match.Value.Split('=')[1], NumberStyles.Any, CultureInfo.InvariantCulture, out degrees);
rotateLayer = new RotateLayer(degrees);
}
@ -281,7 +282,7 @@ namespace ImageProcessor.Processors
{
// Split on angle-
int angle;
int.TryParse(match.Value.Split('-')[1], out angle);
int.TryParse(match.Value.Split('-')[1], NumberStyles.Any, CultureInfo.InvariantCulture, out angle);
return angle;
}

5
src/ImageProcessor/Processors/RoundedCorners.cs

@ -14,6 +14,7 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Text.RegularExpressions;
using ImageProcessor.Imaging;
#endregion
@ -133,7 +134,7 @@ namespace ImageProcessor.Processors
else
{
int radius;
int.TryParse(match.Value.Split('=')[1], out radius);
int.TryParse(match.Value.Split('=')[1], NumberStyles.Any, CultureInfo.InvariantCulture, out radius);
roundedCornerLayer = new RoundedCornerLayer(radius, this.ParseCorner(TopLeftRegex, toParse), this.ParseCorner(TopRightRegex, toParse), this.ParseCorner(BottomLeftRegex, toParse), this.ParseCorner(BottomRightRegex, toParse));
}
@ -295,7 +296,7 @@ namespace ImageProcessor.Processors
{
// Split on radius-
int radius;
int.TryParse(match.Value.Split('-')[1], out radius);
int.TryParse(match.Value.Split('-')[1], NumberStyles.Any, CultureInfo.InvariantCulture, out radius);
return radius;
}

3
src/ImageProcessor/Processors/Saturation.cs

@ -14,6 +14,7 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.Text.RegularExpressions;
#endregion
@ -95,7 +96,7 @@ namespace ImageProcessor.Processors
{
// Set the index on the first instance only.
this.SortOrder = match.Index;
int percentage = int.Parse(match.Value.Split('=')[1]);
int percentage = int.Parse(match.Value.Split('=')[1], CultureInfo.InvariantCulture);
this.DynamicParameter = percentage;
}

5
src/ImageProcessor/Processors/Watermark.cs

@ -16,6 +16,7 @@ namespace ImageProcessor.Processors
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
@ -370,7 +371,7 @@ namespace ImageProcessor.Processors
foreach (Match match in FontSizeRegex.Matches(input))
{
// split on size-value
return int.Parse(match.Value.Split('-')[1]);
return int.Parse(match.Value.Split('-')[1], CultureInfo.InvariantCulture);
}
// Matches the default number in TextLayer.
@ -449,7 +450,7 @@ namespace ImageProcessor.Processors
foreach (Match match in OpacityRegex.Matches(input))
{
// split on opacity-
return int.Parse(match.Value.Split('-')[1]);
return int.Parse(match.Value.Split('-')[1], CultureInfo.InvariantCulture);
}
// full opacity - matches the Textlayer default.

Loading…
Cancel
Save