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
1353315d
Commit
1353315d
authored
Aug 14, 2008
by
Jon Skeet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented TextFormatter
parent
b84310e1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
92 additions
and
1 deletion
+92
-1
ByteString.cs
csharp/ProtocolBuffers/ByteString.cs
+11
-1
ProtocolBuffers.csproj
csharp/ProtocolBuffers/ProtocolBuffers.csproj
+1
-0
TextFormat.cs
csharp/ProtocolBuffers/TextFormat.cs
+0
-0
TextGenerator.cs
csharp/ProtocolBuffers/TextGenerator.cs
+80
-0
No files found.
csharp/ProtocolBuffers/ByteString.cs
View file @
1353315d
...
@@ -15,13 +15,15 @@
...
@@ -15,13 +15,15 @@
// limitations under the License.
// limitations under the License.
using
System.Text
;
using
System.Text
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections
;
namespace
Google.ProtocolBuffers
{
namespace
Google.ProtocolBuffers
{
/// <summary>
/// <summary>
/// Immutable array of bytes.
/// Immutable array of bytes.
/// TODO(jonskeet): Implement the common collection interfaces?
/// TODO(jonskeet): Implement the common collection interfaces?
/// </summary>
/// </summary>
public
sealed
class
ByteString
{
public
sealed
class
ByteString
:
IEnumerable
<
byte
>
{
private
static
readonly
ByteString
empty
=
new
ByteString
(
new
byte
[
0
]);
private
static
readonly
ByteString
empty
=
new
ByteString
(
new
byte
[
0
]);
...
@@ -105,6 +107,14 @@ namespace Google.ProtocolBuffers {
...
@@ -105,6 +107,14 @@ namespace Google.ProtocolBuffers {
return
ToString
(
Encoding
.
UTF8
);
return
ToString
(
Encoding
.
UTF8
);
}
}
public
IEnumerator
<
byte
>
GetEnumerator
()
{
return
((
IEnumerable
<
byte
>)
bytes
).
GetEnumerator
();
}
IEnumerator
IEnumerable
.
GetEnumerator
()
{
return
GetEnumerator
();
}
/// <summary>
/// <summary>
/// Creates a CodedInputStream from this ByteString's data.
/// Creates a CodedInputStream from this ByteString's data.
/// </summary>
/// </summary>
...
...
csharp/ProtocolBuffers/ProtocolBuffers.csproj
View file @
1353315d
...
@@ -87,6 +87,7 @@
...
@@ -87,6 +87,7 @@
<Compile
Include=
"InvalidProtocolBufferException.cs"
/>
<Compile
Include=
"InvalidProtocolBufferException.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"TextFormat.cs"
/>
<Compile
Include=
"TextFormat.cs"
/>
<Compile
Include=
"TextGenerator.cs"
/>
<Compile
Include=
"UninitializedMessageException.cs"
/>
<Compile
Include=
"UninitializedMessageException.cs"
/>
<Compile
Include=
"UnknownField.cs"
/>
<Compile
Include=
"UnknownField.cs"
/>
<Compile
Include=
"UnknownFieldSet.cs"
/>
<Compile
Include=
"UnknownFieldSet.cs"
/>
...
...
csharp/ProtocolBuffers/TextFormat.cs
View file @
1353315d
This diff is collapsed.
Click to expand it.
csharp/ProtocolBuffers/TextGenerator.cs
0 → 100644
View file @
1353315d
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Text
;
namespace
Google.ProtocolBuffers
{
/// <summary>
/// Helper class to control indentation
/// </summary>
internal
class
TextGenerator
{
/// <summary>
/// Writer to write formatted text to.
/// </summary>
private
readonly
TextWriter
writer
;
/// <summary>
/// Keeps track of whether the next piece of text should be indented
/// </summary>
bool
atStartOfLine
=
true
;
/// <summary>
/// Keeps track of the current level of indentation
/// </summary>
readonly
StringBuilder
indent
=
new
StringBuilder
();
/// <summary>
/// Creates a generator writing to the given writer.
/// </summary>
internal
TextGenerator
(
TextWriter
writer
)
{
this
.
writer
=
writer
;
}
/// <summary>
/// Indents text by two spaces. After calling Indent(), two spaces
/// will be inserted at the beginning of each line of text. Indent() may
/// be called multiple times to produce deeper indents.
/// </summary>
internal
void
Indent
()
{
indent
.
Append
(
" "
);
}
/// <summary>
/// Reduces the current indent level by two spaces.
/// </summary>
internal
void
Outdent
()
{
if
(
indent
.
Length
==
0
)
{
throw
new
InvalidOperationException
(
"Too many calls to Outdent()"
);
}
indent
.
Length
-=
2
;
}
/// <summary>
/// Prints the given text to the output stream, indenting at line boundaries.
/// </summary>
/// <param name="text"></param>
public
void
Print
(
string
text
)
{
int
pos
=
0
;
for
(
int
i
=
0
;
i
<
text
.
Length
;
i
++)
{
if
(
text
[
i
]
==
'\n'
)
{
// TODO(jonskeet): Use Environment.NewLine?
Write
(
text
.
Substring
(
pos
,
i
-
pos
+
1
));
pos
=
i
+
1
;
atStartOfLine
=
true
;
}
}
Write
(
text
.
Substring
(
pos
));
}
private
void
Write
(
string
data
)
{
if
(
atStartOfLine
)
{
atStartOfLine
=
false
;
writer
.
Write
(
indent
);
}
writer
.
Write
(
data
);
}
}
}
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