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
a25cef66
Commit
a25cef66
authored
Oct 04, 2011
by
csharptest
Committed by
rogerk
Oct 04, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed issue-35
parent
926f4dd3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
9 deletions
+52
-9
ProgramPreprocess.cs
src/ProtoGen/ProgramPreprocess.cs
+52
-9
No files found.
src/ProtoGen/ProgramPreprocess.cs
View file @
a25cef66
...
@@ -2,6 +2,8 @@ using System;
...
@@ -2,6 +2,8 @@ using System;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.IO
;
using
System.IO
;
using
System.Text
;
using
System.Text.RegularExpressions
;
namespace
Google.ProtocolBuffers.ProtoGen
namespace
Google.ProtocolBuffers.ProtoGen
{
{
...
@@ -172,16 +174,8 @@ namespace Google.ProtocolBuffers.ProtoGen
...
@@ -172,16 +174,8 @@ namespace Google.ProtocolBuffers.ProtoGen
" make sure it is in the PATH, cwd, or exe dir, or use --protoc_dir=..."
);
" make sure it is in the PATH, cwd, or exe dir, or use --protoc_dir=..."
);
}
}
for
(
int
i
=
0
;
i
<
args
.
Length
;
i
++)
{
if
(
args
[
i
].
IndexOf
(
' '
)
>
0
&&
args
[
i
][
0
]
!=
'"'
)
{
args
[
i
]
=
'"'
+
args
[
i
]
+
'"'
;
}
}
ProcessStartInfo
psi
=
new
ProcessStartInfo
(
exeFile
);
ProcessStartInfo
psi
=
new
ProcessStartInfo
(
exeFile
);
psi
.
Arguments
=
String
.
Join
(
" "
,
args
);
psi
.
Arguments
=
EscapeArguments
(
args
);
psi
.
RedirectStandardError
=
true
;
psi
.
RedirectStandardError
=
true
;
psi
.
RedirectStandardInput
=
false
;
psi
.
RedirectStandardInput
=
false
;
psi
.
RedirectStandardOutput
=
true
;
psi
.
RedirectStandardOutput
=
true
;
...
@@ -210,5 +204,53 @@ namespace Google.ProtocolBuffers.ProtoGen
...
@@ -210,5 +204,53 @@ namespace Google.ProtocolBuffers.ProtoGen
}
}
return
process
.
ExitCode
;
return
process
.
ExitCode
;
}
}
/// <summary>
/// Quotes all arguments that contain whitespace, or begin with a quote and returns a single
/// argument string for use with Process.Start().
/// </summary>
/// <remarks>http://csharptest.net/?p=529</remarks>
/// <param name="args">A list of strings for arguments, may not contain null, '\0', '\r', or '\n'</param>
/// <returns>The combined list of escaped/quoted strings</returns>
/// <exception cref="System.ArgumentNullException">Raised when one of the arguments is null</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Raised if an argument contains '\0', '\r', or '\n'</exception>
public
static
string
EscapeArguments
(
params
string
[]
args
)
{
StringBuilder
arguments
=
new
StringBuilder
();
Regex
invalidChar
=
new
Regex
(
"[\x00\x0a\x0d]"
);
// these can not be escaped
Regex
needsQuotes
=
new
Regex
(
@"\s|"""
);
// contains whitespace or two quote characters
Regex
escapeQuote
=
new
Regex
(
@"(\\*)(""|$)"
);
// one or more '\' followed with a quote or end of string
for
(
int
carg
=
0
;
args
!=
null
&&
carg
<
args
.
Length
;
carg
++)
{
if
(
args
[
carg
]
==
null
)
{
throw
new
ArgumentNullException
(
"args["
+
carg
+
"]"
);
}
if
(
invalidChar
.
IsMatch
(
args
[
carg
]))
{
throw
new
ArgumentOutOfRangeException
(
"args["
+
carg
+
"]"
);
}
if
(
args
[
carg
]
==
String
.
Empty
)
{
arguments
.
Append
(
"\"\""
);
}
else
if
(!
needsQuotes
.
IsMatch
(
args
[
carg
]))
{
arguments
.
Append
(
args
[
carg
]);
}
else
{
arguments
.
Append
(
'"'
);
arguments
.
Append
(
escapeQuote
.
Replace
(
args
[
carg
],
m
=>
m
.
Groups
[
1
].
Value
+
m
.
Groups
[
1
].
Value
+
(
m
.
Groups
[
2
].
Value
==
"\""
?
"\\\""
:
""
)
));
arguments
.
Append
(
'"'
);
}
if
(
carg
+
1
<
args
.
Length
)
{
arguments
.
Append
(
' '
);
}
}
return
arguments
.
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