mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-21 04:17:57 +08:00
use invariant culture for parsing all numbers #37
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Tests.Fonts.TrueType.Parser
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -121,9 +122,9 @@
|
||||
|
||||
var match = font.TableHeaders[name];
|
||||
|
||||
var offset = long.Parse(parts[1]);
|
||||
var length = long.Parse(parts[2]);
|
||||
var checksum = long.Parse(parts[3]);
|
||||
var offset = long.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
var length = long.Parse(parts[2], CultureInfo.InvariantCulture);
|
||||
var checksum = long.Parse(parts[3], CultureInfo.InvariantCulture);
|
||||
|
||||
Assert.Equal(offset, match.Offset);
|
||||
Assert.Equal(length, match.Length);
|
||||
@@ -187,9 +188,9 @@
|
||||
{
|
||||
var match = regex.Match(lines[i]);
|
||||
|
||||
var width = decimal.Parse(match.Groups["width"].Value);
|
||||
var height = decimal.Parse(match.Groups["height"].Value);
|
||||
var points = int.Parse(match.Groups["points"].Value);
|
||||
var width = decimal.Parse(match.Groups["width"].Value, CultureInfo.InvariantCulture);
|
||||
var height = decimal.Parse(match.Groups["height"].Value, CultureInfo.InvariantCulture);
|
||||
var points = int.Parse(match.Groups["points"].Value, CultureInfo.InvariantCulture);
|
||||
|
||||
var glyph = font.TableRegister.GlyphTable.Glyphs[i];
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Tests.Integration
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Content;
|
||||
using Xunit;
|
||||
|
||||
@@ -29,15 +30,15 @@
|
||||
throw new ArgumentException($"Expected 6 parts to the line, instead got {parts.Length}");
|
||||
}
|
||||
|
||||
var height = parts.Length < 7 ? 0 : decimal.Parse(parts[6]);
|
||||
var height = parts.Length < 7 ? 0 : decimal.Parse(parts[6], CultureInfo.InvariantCulture);
|
||||
|
||||
return new AssertablePositionData
|
||||
{
|
||||
X = decimal.Parse(parts[0]),
|
||||
Y = decimal.Parse(parts[1]),
|
||||
Width = decimal.Parse(parts[2]),
|
||||
X = decimal.Parse(parts[0], CultureInfo.InvariantCulture),
|
||||
Y = decimal.Parse(parts[1], CultureInfo.InvariantCulture),
|
||||
Width = decimal.Parse(parts[2], CultureInfo.InvariantCulture),
|
||||
Text = parts[3],
|
||||
FontSize = decimal.Parse(parts[4]),
|
||||
FontSize = decimal.Parse(parts[4], CultureInfo.InvariantCulture),
|
||||
FontName = parts[5],
|
||||
Height = height
|
||||
};
|
||||
|
@@ -3,8 +3,10 @@ namespace UglyToad.PdfPig.Tests.Integration
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Content;
|
||||
using Xunit;
|
||||
|
||||
@@ -418,7 +420,7 @@ namespace UglyToad.PdfPig.Tests.Integration
|
||||
209.499 173.25 3.045609 . 0 ArialMT
|
||||
212.543 173.25 3.045609 0 ArialMT";
|
||||
|
||||
return fromOther.Split(new[]{"\r\n", "\r", "\n"}, StringSplitOptions.RemoveEmptyEntries)
|
||||
return fromOther.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(AssertablePositionData.Parse)
|
||||
.ToList();
|
||||
}
|
||||
|
@@ -173,7 +173,7 @@
|
||||
return 0m;
|
||||
}
|
||||
|
||||
return hasExponent ? decimal.Parse(sb.ToString(), NumberStyles.Float) : decimal.Parse(sb.ToString());
|
||||
return hasExponent ? decimal.Parse(sb.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture) : decimal.Parse(sb.ToString(), CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
protected abstract void ApplyOperation(TBuilder builder, List<Operand> operands, OperandKey operandKey, IReadOnlyList<string> stringIndex);
|
||||
|
@@ -98,8 +98,7 @@
|
||||
|
||||
if (codePoint > 0xD7FF && codePoint < 0xE000)
|
||||
{
|
||||
throw new InvalidFontFormatException(
|
||||
$"Unicode character name with disallowed code area: {name}");
|
||||
throw new InvalidFontFormatException($"Unicode character name with disallowed code area: {name}");
|
||||
}
|
||||
|
||||
uniStr.Append((char)codePoint);
|
||||
@@ -115,7 +114,7 @@
|
||||
else if (name.StartsWith("u") && name.Length == 5)
|
||||
{
|
||||
// test for an alternate Unicode name representation uXXXX
|
||||
int codePoint = int.Parse(name.Substring(1), NumberStyles.HexNumber);
|
||||
var codePoint = int.Parse(name.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||
|
||||
if (codePoint > 0xD7FF && codePoint < 0xE000)
|
||||
{
|
||||
|
@@ -63,7 +63,7 @@
|
||||
var value = string.Empty;
|
||||
foreach (var s in values)
|
||||
{
|
||||
var code = int.Parse(s, NumberStyles.HexNumber);
|
||||
var code = int.Parse(s, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||
|
||||
value += char.ConvertFromUtf32(code);
|
||||
}
|
||||
|
@@ -443,7 +443,7 @@
|
||||
{
|
||||
var str = ReadString(input);
|
||||
|
||||
return decimal.Parse(str);
|
||||
return decimal.Parse(str, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private static bool ReadBool(IInputBytes input)
|
||||
@@ -520,67 +520,67 @@
|
||||
{
|
||||
case CharmetricsC:
|
||||
{
|
||||
var code = int.Parse(parts[1]);
|
||||
var code = int.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
metric.CharacterCode = code;
|
||||
break;
|
||||
}
|
||||
case CharmetricsCh:
|
||||
{
|
||||
var code = int.Parse(parts[1], NumberStyles.HexNumber);
|
||||
var code = int.Parse(parts[1], NumberStyles.HexNumber, CultureInfo.InvariantCulture);
|
||||
metric.CharacterCode = code;
|
||||
break;
|
||||
}
|
||||
case CharmetricsWx:
|
||||
{
|
||||
metric.WidthX = decimal.Parse(parts[1]);
|
||||
metric.WidthX = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsW0X:
|
||||
{
|
||||
metric.WidthXDirection0 = decimal.Parse(parts[1]);
|
||||
metric.WidthXDirection0 = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsW1X:
|
||||
{
|
||||
metric.WidthXDirection1 = decimal.Parse(parts[1]);
|
||||
metric.WidthXDirection1 = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsWy:
|
||||
{
|
||||
metric.WidthY = decimal.Parse(parts[1]);
|
||||
metric.WidthY = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsW0Y:
|
||||
{
|
||||
metric.WidthYDirection0 = decimal.Parse(parts[1]);
|
||||
metric.WidthYDirection0 = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsW1Y:
|
||||
{
|
||||
metric.WidthYDirection1 = decimal.Parse(parts[1]);
|
||||
metric.WidthYDirection1 = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsW:
|
||||
{
|
||||
metric.WidthX = decimal.Parse(parts[1]);
|
||||
metric.WidthY = decimal.Parse(parts[2]);
|
||||
metric.WidthX = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
metric.WidthY = decimal.Parse(parts[2], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsW0:
|
||||
{
|
||||
metric.WidthXDirection0 = decimal.Parse(parts[1]);
|
||||
metric.WidthYDirection0 = decimal.Parse(parts[2]);
|
||||
metric.WidthXDirection0 = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
metric.WidthYDirection0 = decimal.Parse(parts[2], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsW1:
|
||||
{
|
||||
metric.WidthXDirection1 = decimal.Parse(parts[1]);
|
||||
metric.WidthYDirection1 = decimal.Parse(parts[2]);
|
||||
metric.WidthXDirection1 = decimal.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
metric.WidthYDirection1 = decimal.Parse(parts[2], CultureInfo.InvariantCulture);
|
||||
break;
|
||||
}
|
||||
case CharmetricsVv:
|
||||
{
|
||||
metric.VVector = new PdfVector(decimal.Parse(parts[1]), decimal.Parse(parts[2]));
|
||||
metric.VVector = new PdfVector(decimal.Parse(parts[1], CultureInfo.InvariantCulture), decimal.Parse(parts[2], CultureInfo.InvariantCulture));
|
||||
break;
|
||||
}
|
||||
case CharmetricsN:
|
||||
@@ -590,10 +590,10 @@
|
||||
}
|
||||
case CharmetricsB:
|
||||
{
|
||||
metric.BoundingBox = new PdfRectangle(decimal.Parse(parts[1]),
|
||||
decimal.Parse(parts[2]),
|
||||
decimal.Parse(parts[3]),
|
||||
decimal.Parse(parts[4]));
|
||||
metric.BoundingBox = new PdfRectangle(decimal.Parse(parts[1], CultureInfo.InvariantCulture),
|
||||
decimal.Parse(parts[2], CultureInfo.InvariantCulture),
|
||||
decimal.Parse(parts[3], CultureInfo.InvariantCulture),
|
||||
decimal.Parse(parts[4], CultureInfo.InvariantCulture));
|
||||
break;
|
||||
}
|
||||
case CharmetricsL:
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
internal class Type1DataToken : Type1Token
|
||||
{
|
||||
@@ -46,7 +47,7 @@
|
||||
|
||||
public decimal AsDecimal()
|
||||
{
|
||||
return decimal.Parse(Text);
|
||||
return decimal.Parse(Text, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public bool AsBool()
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using IO;
|
||||
using PdfPig.Parser.Parts;
|
||||
@@ -312,7 +313,7 @@
|
||||
bytes.Seek(bytes.CurrentOffset - 1);
|
||||
if (radix != null)
|
||||
{
|
||||
var number = Convert.ToInt32(sb.ToString(), int.Parse(radix.ToString()));
|
||||
var number = Convert.ToInt32(sb.ToString(), int.Parse(radix.ToString(), CultureInfo.InvariantCulture));
|
||||
numberToken = new Type1Token(number.ToString(), Type1Token.TokenType.Integer);
|
||||
}
|
||||
else
|
||||
|
@@ -1,6 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Parser.FileStructure
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using Content;
|
||||
using Exceptions;
|
||||
@@ -74,7 +75,7 @@
|
||||
|
||||
var match = VersionRegex.Match(comment.Data);
|
||||
|
||||
if (!match.Success || !decimal.TryParse(match.Groups["version"].Value, out decimal version))
|
||||
if (!match.Success || !decimal.TryParse(match.Groups["version"].Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var version))
|
||||
{
|
||||
if (isLenientParsing)
|
||||
{
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using IO;
|
||||
using Util.JetBrains.Annotations;
|
||||
@@ -127,8 +128,8 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
var obj = long.Parse(objectNumberBytes.ToString());
|
||||
var generation = int.Parse(generationBytes.ToString());
|
||||
var obj = long.Parse(objectNumberBytes.ToString(), CultureInfo.InvariantCulture);
|
||||
var generation = int.Parse(generationBytes.ToString(), CultureInfo.InvariantCulture);
|
||||
|
||||
results[new IndirectReference(obj, generation)] = bytes.CurrentOffset + 1;
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Parser.Parts.CrossReference
|
||||
{
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using IO;
|
||||
using Logging;
|
||||
|
||||
@@ -61,14 +62,12 @@
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
var firstObjectId = long.Parse(parts[0]);
|
||||
var objectCount = int.Parse(parts[1]);
|
||||
var firstObjectId = long.Parse(parts[0], CultureInfo.InvariantCulture);
|
||||
var objectCount = int.Parse(parts[1], CultureInfo.InvariantCulture);
|
||||
|
||||
definition = new TableSubsectionDefinition(firstObjectId, objectCount);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Exceptions;
|
||||
using IO;
|
||||
@@ -162,7 +163,7 @@
|
||||
|
||||
try
|
||||
{
|
||||
retval = long.Parse(longBuffer.ToString());
|
||||
retval = long.Parse(longBuffer.ToString(), CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
@@ -228,7 +229,7 @@
|
||||
|
||||
try
|
||||
{
|
||||
result = int.Parse(intBuffer.ToString());
|
||||
result = int.Parse(intBuffer.ToString(), CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@@ -56,9 +56,8 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
value = decimal.Parse(characters.ToString(), NumberStyles.Any);
|
||||
value = decimal.Parse(characters.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
|
@@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Encryption;
|
||||
@@ -105,7 +106,7 @@
|
||||
{
|
||||
var match = EndsWithNumberRegex.Match(op.Data);
|
||||
|
||||
if (match.Success && int.TryParse(match.Value, out var number))
|
||||
if (match.Success && int.TryParse(match.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out var number))
|
||||
{
|
||||
startPosition = previousTokenPositions[0] + match.Index;
|
||||
objectNumber = new NumericToken(number);
|
||||
|
@@ -40,7 +40,7 @@
|
||||
{
|
||||
if (char.IsNumber(part[0]) || part[0] == '-')
|
||||
{
|
||||
if (decimal.TryParse(part, NumberStyles.AllowLeadingSign, null, out var value))
|
||||
if (decimal.TryParse(part, NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var value))
|
||||
{
|
||||
tokens.Add(new NumericToken(value));
|
||||
}
|
||||
|
Reference in New Issue
Block a user