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
bde57ffc
Commit
bde57ffc
authored
Aug 13, 2011
by
csharptest
Committed by
rogerk
Aug 13, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup per review comments.
parent
5ce95b4b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
47 deletions
+31
-47
unittest_issues.proto
protos/extest/unittest_issues.proto
+1
-1
ExtensionGenerator.cs
src/ProtoGen/ExtensionGenerator.cs
+2
-0
MessageGenerator.cs
src/ProtoGen/MessageGenerator.cs
+2
-0
ICodedInputStream.cs
src/ProtocolBuffers/ICodedInputStream.cs
+1
-1
NameHelpers.cs
src/ProtocolBuffers/NameHelpers.cs
+25
-45
No files found.
protos/extest/unittest_issues.proto
View file @
bde57ffc
...
...
@@ -81,7 +81,7 @@ message AB {
optional
int32
a_b
=
1
;
}
// Similar issue with num
b
eric names
// Similar issue with numeric names
message
NumberField
{
optional
int32
_01
=
1
;
}
...
...
src/ProtoGen/ExtensionGenerator.cs
View file @
bde57ffc
...
...
@@ -76,7 +76,9 @@ namespace Google.ProtocolBuffers.ProtoGen
public
void
Generate
(
TextGenerator
writer
)
{
if
(
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
&&
GetFieldConstantName
(
Descriptor
).
StartsWith
(
"_"
))
{
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
}
writer
.
WriteLine
(
"public const int {0} = {1};"
,
GetFieldConstantName
(
Descriptor
),
Descriptor
.
FieldNumber
);
...
...
src/ProtoGen/MessageGenerator.cs
View file @
bde57ffc
...
...
@@ -247,7 +247,9 @@ namespace Google.ProtocolBuffers.ProtoGen
foreach
(
FieldDescriptor
fieldDescriptor
in
Descriptor
.
Fields
)
{
if
(
Descriptor
.
File
.
CSharpOptions
.
ClsCompliance
&&
GetFieldConstantName
(
fieldDescriptor
).
StartsWith
(
"_"
))
{
writer
.
WriteLine
(
"[global::System.CLSCompliant(false)]"
);
}
// Rats: we lose the debug comment here :(
writer
.
WriteLine
(
"public const int {0} = {1};"
,
GetFieldConstantName
(
fieldDescriptor
),
...
...
src/ProtocolBuffers/ICodedInputStream.cs
View file @
bde57ffc
...
...
@@ -177,7 +177,7 @@ namespace Google.ProtocolBuffers
/// <summary>
/// Reads an array of primitive values into the list, if the wire-type of fieldTag is length-prefixed and the
/// type is num
b
eric, it will read a packed array.
/// type is numeric, it will read a packed array.
/// </summary>
[
CLSCompliant
(
false
)]
void
ReadPrimitiveArray
(
FieldType
fieldType
,
uint
fieldTag
,
string
fieldName
,
ICollection
<
object
>
list
);
...
...
src/ProtocolBuffers/NameHelpers.cs
View file @
bde57ffc
...
...
@@ -35,8 +35,6 @@
#endregion
using
System
;
using
System.Globalization
;
using
System.Text
;
using
System.Text.RegularExpressions
;
namespace
Google.ProtocolBuffers
...
...
@@ -46,6 +44,20 @@ namespace Google.ProtocolBuffers
/// </summary>
public
class
NameHelpers
{
/// <summary>
/// All characters that are not alpha-numeric
/// </summary>
private
static
readonly
Regex
NonAlphaNumericCharacters
=
new
Regex
(
@"[^a-zA-Z0-9]+"
);
/// <summary>
/// Matches lower-case character that follow either an underscore, or a number
/// </summary>
private
static
readonly
Regex
UnderscoreOrNumberWithLowerCase
=
new
Regex
(
@"[0-9_][a-z]"
);
/// <summary>
/// Removes non alpha numeric characters while capitalizing letters that follow
/// a number or underscore. The first letter is always upper case.
/// </summary>
public
static
string
UnderscoresToPascalCase
(
string
input
)
{
string
name
=
UnderscoresToUpperCase
(
input
);
...
...
@@ -60,6 +72,10 @@ namespace Google.ProtocolBuffers
return
name
;
}
/// <summary>
/// Removes non alpha numeric characters while capitalizing letters that follow
/// a number or underscore. The first letter is always lower case.
/// </summary>
public
static
string
UnderscoresToCamelCase
(
string
input
)
{
string
name
=
UnderscoresToUpperCase
(
input
);
...
...
@@ -76,20 +92,24 @@ namespace Google.ProtocolBuffers
/// <summary>
/// Capitalizes any characters following an '_' or a number '0' - '9' and removes
/// all non alpha-num
b
eric characters. If the resulting string begins with a number
/// all non alpha-numeric characters. If the resulting string begins with a number
/// an '_' will be prefixed.
/// </summary>
private
static
string
UnderscoresToUpperCase
(
string
input
)
{
string
name
=
Transform
(
input
,
UnderlineCharacter
,
x
=>
x
.
Value
.
ToUpper
());
name
=
Transform
(
name
,
InvalidCharacters
,
x
=>
String
.
Empty
);
string
name
=
UnderscoreOrNumberWithLowerCase
.
Replace
(
input
,
x
=>
x
.
Value
.
ToUpper
());
name
=
NonAlphaNumericCharacters
.
Replace
(
name
,
String
.
Empty
);
if
(
name
.
Length
==
0
)
{
throw
new
ArgumentException
(
String
.
Format
(
"The field name '{0}' is invalid."
,
input
));
}
// Fields can not start with a number
if
(
Char
.
IsNumber
(
name
[
0
]))
{
name
=
'_'
+
name
;
}
return
name
;
}
...
...
@@ -116,44 +136,5 @@ namespace Google.ProtocolBuffers
}
return
false
;
}
/// <summary>
/// All characters that are not alpha-numberic
/// </summary>
private
static
Regex
InvalidCharacters
=
new
Regex
(
@"[^a-zA-Z0-9]+"
);
/// <summary>
/// Matches lower-case character that follow either an underscore, or a number
/// </summary>
private
static
Regex
UnderlineCharacter
=
new
Regex
(
@"[0-9_][a-z]"
);
/// <summary>
/// Used for text-template transformation where a regex match is replaced in the input string.
/// </summary>
/// <param name="input">The text to perform the replacement upon</param>
/// <param name="pattern">The regex used to perform the match</param>
/// <param name="fnReplace">A delegate that selects the appropriate replacement text</param>
/// <returns>The newly formed text after all replacements are made</returns>
/// <remarks>
/// Originally found at http://csharptest.net/browse/src/Library/Utils/StringUtils.cs#120
/// Republished here by the original author under this project's licensing.
/// </remarks>
private
static
string
Transform
(
string
input
,
Regex
pattern
,
Converter
<
Match
,
string
>
fnReplace
)
{
int
currIx
=
0
;
StringBuilder
sb
=
new
StringBuilder
();
foreach
(
Match
match
in
pattern
.
Matches
(
input
))
{
sb
.
Append
(
input
,
currIx
,
match
.
Index
-
currIx
);
string
replace
=
fnReplace
(
match
);
sb
.
Append
(
replace
);
currIx
=
match
.
Index
+
match
.
Length
;
}
sb
.
Append
(
input
,
currIx
,
input
.
Length
-
currIx
);
return
sb
.
ToString
();
}
}
}
\ No newline at end of file
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