aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers
diff options
context:
space:
mode:
authorJon Skeet <skeet@pobox.com>2009-06-20 20:46:28 +0100
committerJon Skeet <skeet@pobox.com>2009-06-20 20:46:28 +0100
commit60fb63e3704091d0d681181dbab2055f6878f2ea (patch)
treed8ca7572b0d2fb1ce97233b7ddf113bae43cfa0b /src/ProtocolBuffers
parent367217301d7ccd529987d546471c754fa0455ed9 (diff)
downloadprotobuf-60fb63e3704091d0d681181dbab2055f6878f2ea.tar.gz
protobuf-60fb63e3704091d0d681181dbab2055f6878f2ea.tar.bz2
protobuf-60fb63e3704091d0d681181dbab2055f6878f2ea.zip
Initial Silverlight compatibility work
Diffstat (limited to 'src/ProtocolBuffers')
-rw-r--r--src/ProtocolBuffers/ByteString.cs2
-rw-r--r--src/ProtocolBuffers/CodedInputStream.cs4
-rw-r--r--src/ProtocolBuffers/FieldSet.cs6
-rw-r--r--src/ProtocolBuffers/GeneratedMessage.cs4
-rw-r--r--src/ProtocolBuffers/NameHelpers.cs5
-rw-r--r--src/ProtocolBuffers/TextFormat.cs2
-rw-r--r--src/ProtocolBuffers/TextTokenizer.cs14
-rw-r--r--src/ProtocolBuffers/UnknownFieldSet.cs4
8 files changed, 24 insertions, 17 deletions
diff --git a/src/ProtocolBuffers/ByteString.cs b/src/ProtocolBuffers/ByteString.cs
index 0d67a539..0d027b78 100644
--- a/src/ProtocolBuffers/ByteString.cs
+++ b/src/ProtocolBuffers/ByteString.cs
@@ -116,7 +116,7 @@ namespace Google.ProtocolBuffers {
}
public string ToString(Encoding encoding) {
- return encoding.GetString(bytes);
+ return encoding.GetString(bytes, 0, bytes.Length);
}
public string ToStringUtf8() {
diff --git a/src/ProtocolBuffers/CodedInputStream.cs b/src/ProtocolBuffers/CodedInputStream.cs
index 132773c9..313bddf3 100644
--- a/src/ProtocolBuffers/CodedInputStream.cs
+++ b/src/ProtocolBuffers/CodedInputStream.cs
@@ -235,8 +235,8 @@ namespace Google.ProtocolBuffers {
bufferPos += size;
return result;
}
- // Slow path: Build a byte array first then copy it.
- return Encoding.UTF8.GetString(ReadRawBytes(size));
+ // Slow path: Build a byte array first then copy it.
+ return Encoding.UTF8.GetString(ReadRawBytes(size), 0, size);
}
/// <summary>
diff --git a/src/ProtocolBuffers/FieldSet.cs b/src/ProtocolBuffers/FieldSet.cs
index 39b2a696..f084afa2 100644
--- a/src/ProtocolBuffers/FieldSet.cs
+++ b/src/ProtocolBuffers/FieldSet.cs
@@ -62,8 +62,8 @@ namespace Google.ProtocolBuffers {
}
public static FieldSet CreateInstance() {
- // Use SortedList to keep fields in the canonical order
- return new FieldSet(new SortedList<FieldDescriptor, object>());
+ // Use SortedDictionary to keep fields in the canonical order
+ return new FieldSet(new SortedDictionary<FieldDescriptor, object>());
}
/// <summary>
@@ -82,7 +82,7 @@ namespace Google.ProtocolBuffers {
}
if (hasRepeats) {
- var tmp = new SortedList<FieldDescriptor, object>();
+ var tmp = new SortedDictionary<FieldDescriptor, object>();
foreach (KeyValuePair<FieldDescriptor, object> entry in fields) {
IList<object> list = entry.Value as IList<object>;
tmp[entry.Key] = list == null ? entry.Value : Lists.AsReadOnly(list);
diff --git a/src/ProtocolBuffers/GeneratedMessage.cs b/src/ProtocolBuffers/GeneratedMessage.cs
index d8747599..055bc722 100644
--- a/src/ProtocolBuffers/GeneratedMessage.cs
+++ b/src/ProtocolBuffers/GeneratedMessage.cs
@@ -66,8 +66,8 @@ namespace Google.ProtocolBuffers {
internal IDictionary<FieldDescriptor, Object> GetMutableFieldMap() {
- // Use a SortedList so we'll end up serializing fields in order
- var ret = new SortedList<FieldDescriptor, object>();
+ // Use a SortedDictionary so we'll end up serializing fields in order
+ var ret = new SortedDictionary<FieldDescriptor, object>();
MessageDescriptor descriptor = DescriptorForType;
foreach (FieldDescriptor field in descriptor.Fields) {
IFieldAccessor<TMessage, TBuilder> accessor = InternalFieldAccessors[field];
diff --git a/src/ProtocolBuffers/NameHelpers.cs b/src/ProtocolBuffers/NameHelpers.cs
index 8b297f95..cf4931d0 100644
--- a/src/ProtocolBuffers/NameHelpers.cs
+++ b/src/ProtocolBuffers/NameHelpers.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
+using System.Globalization;
namespace Google.ProtocolBuffers {
/// <summary>
@@ -31,7 +32,7 @@ namespace Google.ProtocolBuffers {
char c = input[i];
if ('a' <= c && c <= 'z') {
if (capitaliseNext) {
- result.Append(char.ToUpperInvariant(c));
+ result.Append(char.ToUpper(c, CultureInfo.InvariantCulture));
} else {
result.Append(c);
}
@@ -40,7 +41,7 @@ namespace Google.ProtocolBuffers {
if (i == 0 && !pascal) {
// Force first letter to lower-case unless explicitly told to
// capitalize it.
- result.Append(char.ToLowerInvariant(c));
+ result.Append(char.ToLower(c, CultureInfo.InvariantCulture));
} else {
// Capital letters after the first are left as-is.
result.Append(c);
diff --git a/src/ProtocolBuffers/TextFormat.cs b/src/ProtocolBuffers/TextFormat.cs
index fc8030f7..ba7b467e 100644
--- a/src/ProtocolBuffers/TextFormat.cs
+++ b/src/ProtocolBuffers/TextFormat.cs
@@ -537,7 +537,7 @@ namespace Google.ProtocolBuffers {
if (field == null) {
// Explicitly specify the invariant culture so that this code does not break when
// executing in Turkey.
- String lowerName = name.ToLowerInvariant();
+ String lowerName = name.ToLower(CultureInfo.InvariantCulture);
field = type.FindDescriptor<FieldDescriptor>(lowerName);
// If the case-insensitive match worked but the field is NOT a group,
// TODO(jonskeet): What? Java comment ends here!
diff --git a/src/ProtocolBuffers/TextTokenizer.cs b/src/ProtocolBuffers/TextTokenizer.cs
index 8d639990..d25a5874 100644
--- a/src/ProtocolBuffers/TextTokenizer.cs
+++ b/src/ProtocolBuffers/TextTokenizer.cs
@@ -69,9 +69,15 @@ namespace Google.ProtocolBuffers {
/// </summary>
private int previousColumn = 0;
+#if SILVERLIGHT
+ private const RegexOptions CompiledRegexWhereAvailable = RegexOptions.None;
+#else
+ private const RegexOptions CompiledRegexWhereAvailable = RegexOptions.Compiled;
+#endif
+
// Note: atomic groups used to mimic possessive quantifiers in Java in both of these regexes
private static readonly Regex WhitespaceAndCommentPattern = new Regex("\\G(?>(\\s|(#.*$))+)",
- RegexOptions.Compiled | RegexOptions.Multiline);
+ CompiledRegexWhereAvailable | RegexOptions.Multiline);
private static readonly Regex TokenPattern = new Regex(
"\\G[a-zA-Z_](?>[0-9a-zA-Z_+-]*)|" + // an identifier
"\\G[0-9+-](?>[0-9a-zA-Z_.+-]*)|" + // a number
@@ -79,9 +85,9 @@ namespace Google.ProtocolBuffers {
"\\G\'(?>([^\"\\\n\\\\]|\\\\.)*)(\'|\\\\?$)", // a single-quoted string
RegexOptions.Compiled | RegexOptions.Multiline);
- private static readonly Regex DoubleInfinity = new Regex("^-?inf(inity)?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
- private static readonly Regex FloatInfinity = new Regex("^-?inf(inity)?f?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
- private static readonly Regex FloatNan = new Regex("^nanf?$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
+ private static readonly Regex DoubleInfinity = new Regex("^-?inf(inity)?$", CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
+ private static readonly Regex FloatInfinity = new Regex("^-?inf(inity)?f?$", CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
+ private static readonly Regex FloatNan = new Regex("^nanf?$", CompiledRegexWhereAvailable | RegexOptions.IgnoreCase);
/** Construct a tokenizer that parses tokens from the given text. */
public TextTokenizer(string text) {
diff --git a/src/ProtocolBuffers/UnknownFieldSet.cs b/src/ProtocolBuffers/UnknownFieldSet.cs
index 9de09709..f0655103 100644
--- a/src/ProtocolBuffers/UnknownFieldSet.cs
+++ b/src/ProtocolBuffers/UnknownFieldSet.cs
@@ -240,10 +240,10 @@ namespace Google.ProtocolBuffers {
public sealed class Builder
{
/// <summary>
- /// Mapping from number to field. Note that by using a SortedList we ensure
+ /// Mapping from number to field. Note that by using a SortedDictionary we ensure
/// that the fields will be serialized in ascending order.
/// </summary>
- private IDictionary<int, UnknownField> fields = new SortedList<int, UnknownField>();
+ private IDictionary<int, UnknownField> fields = new SortedDictionary<int, UnknownField>();
// Optimization: We keep around a builder for the last field that was
// modified so that we can efficiently add to it multiple times in a