Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
d33bff04
Commit
d33bff04
authored
May 11, 2009
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed i18n issues with numbers
parent
7a66a6d3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
72 additions
and
12 deletions
+72
-12
GeneratedMessageTest.cs
src/ProtocolBuffers.Test/GeneratedMessageTest.cs
+8
-4
TestUtil.cs
src/ProtocolBuffers.Test/TestUtil.cs
+16
-0
TextFormatTest.cs
src/ProtocolBuffers.Test/TextFormatTest.cs
+11
-5
FieldDescriptor.cs
src/ProtocolBuffers/Descriptors/FieldDescriptor.cs
+2
-2
TextFormat.cs
src/ProtocolBuffers/TextFormat.cs
+35
-0
TextTokenizer.cs
src/ProtocolBuffers/TextTokenizer.cs
+0
-1
No files found.
src/ProtocolBuffers.Test/GeneratedMessageTest.cs
View file @
d33bff04
...
@@ -228,8 +228,10 @@ namespace Google.ProtocolBuffers {
...
@@ -228,8 +228,10 @@ namespace Google.ProtocolBuffers {
[
Test
]
[
Test
]
public
void
ReflectionDefaults
()
{
public
void
ReflectionDefaults
()
{
reflectionTester
.
AssertClearViaReflection
(
TestAllTypes
.
DefaultInstance
);
TestUtil
.
TestInMultipleCultures
(()
=>
{
reflectionTester
.
AssertClearViaReflection
(
TestAllTypes
.
CreateBuilder
().
Build
());
reflectionTester
.
AssertClearViaReflection
(
TestAllTypes
.
DefaultInstance
);
reflectionTester
.
AssertClearViaReflection
(
TestAllTypes
.
CreateBuilder
().
Build
());
});
}
}
// =================================================================
// =================================================================
// Extensions.
// Extensions.
...
@@ -296,8 +298,10 @@ namespace Google.ProtocolBuffers {
...
@@ -296,8 +298,10 @@ namespace Google.ProtocolBuffers {
[
Test
]
[
Test
]
public
void
ExtensionReflectionDefaults
()
{
public
void
ExtensionReflectionDefaults
()
{
extensionsReflectionTester
.
AssertClearViaReflection
(
TestAllExtensions
.
DefaultInstance
);
TestUtil
.
TestInMultipleCultures
(()
=>
{
extensionsReflectionTester
.
AssertClearViaReflection
(
TestAllExtensions
.
CreateBuilder
().
Build
());
extensionsReflectionTester
.
AssertClearViaReflection
(
TestAllExtensions
.
DefaultInstance
);
extensionsReflectionTester
.
AssertClearViaReflection
(
TestAllExtensions
.
CreateBuilder
().
Build
());
});
}
}
[
Test
]
[
Test
]
...
...
src/ProtocolBuffers.Test/TestUtil.cs
View file @
d33bff04
...
@@ -31,10 +31,12 @@
...
@@ -31,10 +31,12 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.IO
;
using
System.IO
;
using
System.Text
;
using
System.Text
;
using
Google.ProtocolBuffers.TestProtos
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
using
NUnit.Framework
;
using
System.Threading
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
internal
static
class
TestUtil
{
internal
static
class
TestUtil
{
...
@@ -1577,6 +1579,20 @@ namespace Google.ProtocolBuffers {
...
@@ -1577,6 +1579,20 @@ namespace Google.ProtocolBuffers {
}
}
return
goldenPackedFieldsMessage
;
return
goldenPackedFieldsMessage
;
}
}
private
static
readonly
string
[]
TestCultures
=
{
"en-US"
,
"en-GB"
,
"fr-FR"
,
"de-DE"
};
public
static
void
TestInMultipleCultures
(
Action
test
)
{
CultureInfo
originalCulture
=
Thread
.
CurrentThread
.
CurrentCulture
;
foreach
(
string
culture
in
TestCultures
)
{
try
{
Thread
.
CurrentThread
.
CurrentCulture
=
new
CultureInfo
(
culture
);
test
();
}
finally
{
Thread
.
CurrentThread
.
CurrentCulture
=
originalCulture
;
}
}
}
/// <summary>
/// <summary>
/// Helper to construct a byte array from a bunch of bytes.
/// Helper to construct a byte array from a bunch of bytes.
...
...
src/ProtocolBuffers.Test/TextFormatTest.cs
View file @
d33bff04
...
@@ -34,6 +34,8 @@ using System.IO;
...
@@ -34,6 +34,8 @@ using System.IO;
using
System.Text
;
using
System.Text
;
using
Google.ProtocolBuffers.TestProtos
;
using
Google.ProtocolBuffers.TestProtos
;
using
NUnit.Framework
;
using
NUnit.Framework
;
using
System.Globalization
;
using
System.Threading
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
[
TestFixture
]
[
TestFixture
]
...
@@ -82,8 +84,10 @@ namespace Google.ProtocolBuffers {
...
@@ -82,8 +84,10 @@ namespace Google.ProtocolBuffers {
/// </summary>
/// </summary>
[
Test
]
[
Test
]
public
void
PrintMessage
()
{
public
void
PrintMessage
()
{
string
text
=
TextFormat
.
PrintToString
(
TestUtil
.
GetAllSet
());
TestUtil
.
TestInMultipleCultures
(()
=>
{
Assert
.
AreEqual
(
AllFieldsSetText
.
Replace
(
"\r\n"
,
"\n"
),
text
.
Replace
(
"\r\n"
,
"\n"
));
string
text
=
TextFormat
.
PrintToString
(
TestUtil
.
GetAllSet
());
Assert
.
AreEqual
(
AllFieldsSetText
.
Replace
(
"\r\n"
,
"\n"
),
text
.
Replace
(
"\r\n"
,
"\n"
));
});
}
}
/// <summary>
/// <summary>
...
@@ -213,9 +217,11 @@ namespace Google.ProtocolBuffers {
...
@@ -213,9 +217,11 @@ namespace Google.ProtocolBuffers {
[
Test
]
[
Test
]
public
void
Parse
()
{
public
void
Parse
()
{
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
CreateBuilder
();
TestUtil
.
TestInMultipleCultures
(()
=>
{
TextFormat
.
Merge
(
AllFieldsSetText
,
builder
);
TestAllTypes
.
Builder
builder
=
TestAllTypes
.
CreateBuilder
();
TestUtil
.
AssertAllFieldsSet
(
builder
.
Build
());
TextFormat
.
Merge
(
AllFieldsSetText
,
builder
);
TestUtil
.
AssertAllFieldsSet
(
builder
.
Build
());
});
}
}
[
Test
]
[
Test
]
...
...
src/ProtocolBuffers/Descriptors/FieldDescriptor.cs
View file @
d33bff04
...
@@ -422,10 +422,10 @@ namespace Google.ProtocolBuffers.Descriptors {
...
@@ -422,10 +422,10 @@ namespace Google.ProtocolBuffers.Descriptors {
defaultValue
=
TextFormat
.
ParseUInt64
(
Proto
.
DefaultValue
);
defaultValue
=
TextFormat
.
ParseUInt64
(
Proto
.
DefaultValue
);
break
;
break
;
case
FieldType
.
Float
:
case
FieldType
.
Float
:
defaultValue
=
float
.
Parse
(
Proto
.
DefaultValue
);
defaultValue
=
TextFormat
.
ParseFloat
(
Proto
.
DefaultValue
);
break
;
break
;
case
FieldType
.
Double
:
case
FieldType
.
Double
:
defaultValue
=
double
.
Pars
e
(
Proto
.
DefaultValue
);
defaultValue
=
TextFormat
.
ParseDoubl
e
(
Proto
.
DefaultValue
);
break
;
break
;
case
FieldType
.
Bool
:
case
FieldType
.
Bool
:
if
(
Proto
.
DefaultValue
==
"true"
)
{
if
(
Proto
.
DefaultValue
==
"true"
)
{
...
...
src/ProtocolBuffers/TextFormat.cs
View file @
d33bff04
...
@@ -231,6 +231,41 @@ namespace Google.ProtocolBuffers {
...
@@ -231,6 +231,41 @@ namespace Google.ProtocolBuffers {
return
(
int
)
ParseInteger
(
text
,
true
,
false
);
return
(
int
)
ParseInteger
(
text
,
true
,
false
);
}
}
internal
static
float
ParseFloat
(
string
text
)
{
switch
(
text
)
{
case
"-inf"
:
case
"-infinity"
:
case
"-inff"
:
case
"-infinityf"
:
return
float
.
NegativeInfinity
;
case
"inf"
:
case
"infinity"
:
case
"inff"
:
case
"infinityf"
:
return
float
.
PositiveInfinity
;
case
"nan"
:
case
"nanf"
:
return
float
.
NaN
;
default
:
return
float
.
Parse
(
text
,
CultureInfo
.
InvariantCulture
);
}
}
internal
static
double
ParseDouble
(
string
text
)
{
switch
(
text
)
{
case
"-inf"
:
case
"-infinity"
:
return
double
.
NegativeInfinity
;
case
"inf"
:
case
"infinity"
:
return
double
.
PositiveInfinity
;
case
"nan"
:
return
double
.
NaN
;
default
:
return
double
.
Parse
(
text
,
CultureInfo
.
InvariantCulture
);
}
}
/// <summary>
/// <summary>
/// Parses an integer in hex (leading 0x), decimal (no prefix) or octal (leading 0).
/// Parses an integer in hex (leading 0x), decimal (no prefix) or octal (leading 0).
/// Only a negative sign is permitted, and it must come before the radix indicator.
/// Only a negative sign is permitted, and it must come before the radix indicator.
...
...
src/ProtocolBuffers/TextTokenizer.cs
View file @
d33bff04
...
@@ -293,7 +293,6 @@ namespace Google.ProtocolBuffers {
...
@@ -293,7 +293,6 @@ namespace Google.ProtocolBuffers {
/// Otherwise, throw a FormatException.
/// Otherwise, throw a FormatException.
/// </summary>
/// </summary>
public
float
ConsumeFloat
()
{
public
float
ConsumeFloat
()
{
// We need to parse infinity and nan separately because
// We need to parse infinity and nan separately because
// Float.parseFloat() does not accept "inf", "infinity", or "nan".
// Float.parseFloat() does not accept "inf", "infinity", or "nan".
if
(
FloatInfinity
.
IsMatch
(
currentToken
))
{
if
(
FloatInfinity
.
IsMatch
(
currentToken
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment