From 0be785fb81799a5d42f95c13d88ebf977b5e0270 Mon Sep 17 00:00:00 2001
From: Yuki Izumi <[email protected]>
Date: Sat, 10 May 2014 16:04:25 +1000
Subject: [PATCH] Use CultureInfo.InvariantCulture when parsing.
---
source/FileFormatWavefront/FileFormatMtl.cs | 19 ++++++++++---------
source/FileFormatWavefront/FileFormatObj.cs | 25 +++++++++++++------------
2 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/source/FileFormatWavefront/FileFormatMtl.cs b/source/FileFormatWavefront/FileFormatMtl.cs
index 368b334..e744ade 100644
--- a/source/FileFormatWavefront/FileFormatMtl.cs
+++ b/source/FileFormatWavefront/FileFormatMtl.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
+using System.Globalization;
using System.IO;
using System.Linq;
using FileFormatWavefront.Extensions;
@@ -87,15 +88,15 @@ private static FileLoadResult<List<Material>> Read(TextReader reader, string pat
}
else if (lineType.IsLineType(LineTypeMaterialShininess))
{
- currentMaterial.Shininess = float.Parse(lineData);
+ currentMaterial.Shininess = float.Parse(lineData, CultureInfo.InvariantCulture);
}
else if (lineType.IsLineType(LineTypeOpticalDensity))
{
- currentMaterial.OpticalDensity = float.Parse(lineData);
+ currentMaterial.OpticalDensity = float.Parse(lineData, CultureInfo.InvariantCulture);
}
else if (lineType.IsLineType(LineTypeBumpStrength))
{
- currentMaterial.BumpStrength = float.Parse(lineData);
+ currentMaterial.BumpStrength = float.Parse(lineData, CultureInfo.InvariantCulture);
}
else if (lineType.IsLineType(LineTypeTextureMapAmbient))
{
@@ -124,11 +125,11 @@ private static FileLoadResult<List<Material>> Read(TextReader reader, string pat
else if (lineType.IsLineType(LineTypeDissolve) || lineType.IsLineType(LineTypeTransparent))
{
// Read the transparency.
- currentMaterial.Transparency = float.Parse(lineData);
+ currentMaterial.Transparency = float.Parse(lineData, CultureInfo.InvariantCulture);
}
else if(lineType.IsLineType(LineTypeIlluminationModel))
{
- currentMaterial.IlluminationModel = int.Parse(lineData);
+ currentMaterial.IlluminationModel = int.Parse(lineData, CultureInfo.InvariantCulture);
}
else
{
@@ -197,10 +198,10 @@ private static Colour ReadColour(string lineData)
var colourParts = lineData.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
return new Colour
{
- r = float.Parse(colourParts[0]),
- g = float.Parse(colourParts[1]),
- b = float.Parse(colourParts[2]),
- a = colourParts.Length == 4 ? float.Parse(colourParts[3]) : 1.0f,
+ r = float.Parse(colourParts[0], CultureInfo.InvariantCulture),
+ g = float.Parse(colourParts[1], CultureInfo.InvariantCulture),
+ b = float.Parse(colourParts[2], CultureInfo.InvariantCulture),
+ a = colourParts.Length == 4 ? float.Parse(colourParts[3], CultureInfo.InvariantCulture) : 1.0f,
};
}
diff --git a/source/FileFormatWavefront/FileFormatObj.cs b/source/FileFormatWavefront/FileFormatObj.cs
index 178accf..ed64712 100644
--- a/source/FileFormatWavefront/FileFormatObj.cs
+++ b/source/FileFormatWavefront/FileFormatObj.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using FileFormatWavefront.Extensions;
@@ -90,8 +91,8 @@ private static FileLoadResult<Scene> ReadScene(StreamReader reader, string path,
// Add the UV.
uvs.Add(new UV
{
- u = float.Parse(dataStrings[0]),
- v = float.Parse(dataStrings[1])
+ u = float.Parse(dataStrings[0], CultureInfo.InvariantCulture),
+ v = float.Parse(dataStrings[1], CultureInfo.InvariantCulture)
});
}
catch (Exception exception)
@@ -108,9 +109,9 @@ private static FileLoadResult<Scene> ReadScene(StreamReader reader, string path,
var dataStrings = lineData.Split(dataSeparators, StringSplitOptions.RemoveEmptyEntries);
normals.Add(new Vertex
{
- x = float.Parse(dataStrings[0]),
- y = float.Parse(dataStrings[1]),
- z = float.Parse(dataStrings[2])
+ x = float.Parse(dataStrings[0], CultureInfo.InvariantCulture),
+ y = float.Parse(dataStrings[1], CultureInfo.InvariantCulture),
+ z = float.Parse(dataStrings[2], CultureInfo.InvariantCulture)
});
}
catch (Exception exception)
@@ -127,9 +128,9 @@ private static FileLoadResult<Scene> ReadScene(StreamReader reader, string path,
var dataStrings = lineData.Split(dataSeparators, StringSplitOptions.RemoveEmptyEntries);
vertices.Add(new Vertex
{
- x = float.Parse(dataStrings[0]),
- y = float.Parse(dataStrings[1]),
- z = float.Parse(dataStrings[2])
+ x = float.Parse(dataStrings[0], CultureInfo.InvariantCulture),
+ y = float.Parse(dataStrings[1], CultureInfo.InvariantCulture),
+ z = float.Parse(dataStrings[2], CultureInfo.InvariantCulture)
});
}
catch (Exception exception)
@@ -150,9 +151,9 @@ private static FileLoadResult<Scene> ReadScene(StreamReader reader, string path,
{
// Split the parts.
var parts = indexString.Split(new[] { '/' }, StringSplitOptions.None);
- var vertex = MapIndex(vertices.Count, int.Parse(parts[0]));
- var uv = (parts.Length > 1 && parts[1].Length > 0) ? (int?)MapIndex(uvs.Count, int.Parse(parts[1])) : null;
- var normal = (parts.Length > 2 && parts[2].Length > 0) ? (int?)MapIndex(normals.Count, int.Parse(parts[2])) : null;
+ var vertex = MapIndex(vertices.Count, int.Parse(parts[0], CultureInfo.InvariantCulture));
+ var uv = (parts.Length > 1 && parts[1].Length > 0) ? (int?)MapIndex(uvs.Count, int.Parse(parts[1], CultureInfo.InvariantCulture)) : null;
+ var normal = (parts.Length > 2 && parts[2].Length > 0) ? (int?)MapIndex(normals.Count, int.Parse(parts[2], CultureInfo.InvariantCulture)) : null;
indices.Add(new Index
{
vertex = vertex,
@@ -219,7 +220,7 @@ private static FileLoadResult<Scene> ReadScene(StreamReader reader, string path,
{
// The smoothing group is an int, if we can get it.
int smoothingGroup;
- if(int.TryParse(lineData, out smoothingGroup))
+ if(int.TryParse(lineData, NumberStyles.Integer, CultureInfo.InvariantCulture, out smoothingGroup))
currentGroup.SetSmoothingGroup(smoothingGroup);
currentGroup.SetSmoothingGroup(null);
}
--
1.8.4.msysgit.0