[jayrock] 4 new revisions pushed by azizatif on 2011-04-18 21:29 GMT

1 view
Skip to first unread message

jay...@googlecode.com

unread,
Apr 18, 2011, 5:29:39 PM4/18/11
to jayrock...@googlegroups.com
4 new revisions:

Revision: eca68b09bca9
Author: azizatif
Date: Sat Apr 16 03:42:11 2011
Log: Fixed typos in doc summaries of FreeJsonMemberReadingHelper.
http://code.google.com/p/jayrock/source/detail?r=eca68b09bca9

Revision: a868d157fb09
Author: Chip Salzenberg <ch...@pobox.com>
Date: Sun Apr 17 16:20:24 2011
Log: avoid System.Xml dependencies; properly document date parsing
limitati...
http://code.google.com/p/jayrock/source/detail?r=a868d157fb09

Revision: ae67d2540d5c
Author: Chip Salzenberg <ch...@pobox.com>
Date: Sun Apr 17 16:27:53 2011
Log: Supplement case policy with underscore policy when renaming
members
http://code.google.com/p/jayrock/source/detail?r=ae67d2540d5c

Revision: e8c40fa10d52
Author: azizatif
Date: Mon Apr 18 14:27:45 2011
Log: Merged
http://code.google.com/p/jayrock/source/detail?r=e8c40fa10d52

==============================================================================
Revision: eca68b09bca9
Author: azizatif
Date: Sat Apr 16 03:42:11 2011
Log: Fixed typos in doc summaries of FreeJsonMemberReadingHelper.
http://code.google.com/p/jayrock/source/detail?r=eca68b09bca9

Modified:
/src/Jayrock.Json/Json/FreeJsonMemberReadingHelper.cs

=======================================
--- /src/Jayrock.Json/Json/FreeJsonMemberReadingHelper.cs Sat Apr 16
03:31:20 2011
+++ /src/Jayrock.Json/Json/FreeJsonMemberReadingHelper.cs Sat Apr 16
03:42:11 2011
@@ -45,7 +45,7 @@
/// the underlying JSON data is tokenized and yielded sequentially.
/// When reading a JSON object, members must be processed in the order
/// in which they are yielded by the underlying reader. If an
- /// application requires somes members of a JSON object to correctly
+ /// application requires some members of a JSON object to correctly
/// process the remaining members then those member may need to be read
/// in advance to prepare for further processing. For example, suppose
/// the JSON object
<c>{ "type": "date", "format": "M/d/yyyy", "value": "5/5/2008" }</c>
@@ -69,7 +69,7 @@
/// also-buffered <c>value</c> member. This is where
/// <see cref="FreeJsonMemberReadingHelper"/> can help tremendously.
/// The application can call its <see cref="ReadMember"/> method to
- /// read members the natural order of processing (e.g., <c>type</c>,
+ /// read members in the natural order of processing (e.g., <c>type</c>,
/// <c>format</c> and <c>value</c>) rather than how they have been
/// actually ordered by some source. <see
cref="FreeJsonMemberReadingHelper"/>
/// will buffer or stream from the underlying <see cref="JsonReader"/>
@@ -119,7 +119,7 @@

/// <summary>
/// Gets a reader than can be used to read remaining members,
- /// which could included buffered and non-buffered members.
+ /// which could include buffered and non-buffered members.
/// </summary>

public JsonReader GetTailReader()
@@ -160,7 +160,7 @@
/// <summary>
/// Attempts to locate a member with a given (case-sensitive) name
/// and returns a <see cref="JsonReader"/> that can be used to read
- /// the value. Otherwise it return <c>null</c>.
+ /// the value. Otherwise it returns <c>null</c>.
/// </summary>
/// <remarks>
/// The caller should not use the returned <see cref="JsonReader"/>

==============================================================================
Revision: a868d157fb09
Author: Chip Salzenberg <ch...@pobox.com>
Date: Sun Apr 17 16:20:24 2011
Log: avoid System.Xml dependencies; properly document date parsing
limitations
http://code.google.com/p/jayrock/source/detail?r=a868d157fb09

Modified:
/src/Jayrock.Json/Json/Conversion/Converters/DateTimeImporter.cs

=======================================
--- /src/Jayrock.Json/Json/Conversion/Converters/DateTimeImporter.cs Fri
Apr 15 16:09:54 2011
+++ /src/Jayrock.Json/Json/Conversion/Converters/DateTimeImporter.cs Sun
Apr 17 16:20:24 2011
@@ -28,7 +28,6 @@
using System.Diagnostics;
using System.Globalization;
using System.Text.RegularExpressions;
- using System.Xml;

#endregion

@@ -51,8 +50,10 @@
// have elapsed since midnight 01 January, 1970 UTC.
// See also:
http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
//
-
- Match match = Regex.Match(reader.Text, @"\A \/ Date \(
([0-9]+) \) \/ \z",
+ // TODO: MS Ajax format requires the slashes to be
escaped, but we have no information here whether
+ // any characters were escaped. So we have to
assume they were. Given that we wouldn't be in
+ // this importer unless we expected a DateTime, it's
probably safe enough.
+ Match match = Regex.Match(reader.Text, @"\A / Date \(
(-?[0-9]+) \) / \z",
RegexOptions.IgnorePatternWhitespace
| RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant);
@@ -76,11 +77,7 @@
return ReadReturning(reader, time);
}

- return ReadReturning(reader,
XmlConvert.ToDateTime(reader.Text
- #if !NET_1_0 && !NET_1_1
- , XmlDateTimeSerializationMode.Local
- #endif
- ));
+ return ReadReturning(reader, DateTime.Parse(reader.Text,
CultureInfo.InvariantCulture));
}
catch (FormatException e)
{

==============================================================================
Revision: ae67d2540d5c
Author: Chip Salzenberg <ch...@pobox.com>
Date: Sun Apr 17 16:27:53 2011
Log: Supplement case policy with underscore policy when renaming
members
http://code.google.com/p/jayrock/source/detail?r=ae67d2540d5c

Modified:
/src/Jayrock.Json/Json/Conversion/JsonMemberNamingConventionAttribute.cs
/tests/Jayrock/Json/Conversion/TestJsonMemberNamingConventionAttribute.cs

=======================================
---
/src/Jayrock.Json/Json/Conversion/JsonMemberNamingConventionAttribute.cs
Fri Apr 15 16:09:54 2011
+++
/src/Jayrock.Json/Json/Conversion/JsonMemberNamingConventionAttribute.cs
Sun Apr 17 16:27:53 2011
@@ -40,12 +40,20 @@
Upper, // WORLDWIDEWEB
Lower // worldwideweb
}
+ [ Serializable ]
+ public enum UnderscoreConvention
+ {
+ None,
+ Prefix, // _WorldWideWeb (if Pascal)
+ Separate // World_Wide_Web (if Pascal)
+ }

[ Serializable ]
[ AttributeUsage(AttributeTargets.Property | AttributeTargets.Field) ]
public sealed class JsonMemberNamingConventionAttribute : Attribute,
IPropertyDescriptorCustomization
{
private NamingConvention _convention;
+ private UnderscoreConvention _underscores;

public JsonMemberNamingConventionAttribute() {}

@@ -53,31 +61,64 @@
{
_convention = convention;
}
+
+ public JsonMemberNamingConventionAttribute(NamingConvention
naming, UnderscoreConvention underscores)
+ {
+ _convention = naming;
+ _underscores = underscores;
+ }

public NamingConvention Convention
{
get { return _convention; }
set { _convention = value; }
}
+
+ public UnderscoreConvention Underscores {
+ get { return _underscores; }
+ set { _underscores = value; }
+ }

void IPropertyDescriptorCustomization.Apply(PropertyDescriptor
property)
{
if (property == null)
throw new ArgumentNullException("property");

+ if (Convention == NamingConvention.None && Underscores ==
UnderscoreConvention.None)
+ return;
+
string name = property.Name;
+
+ switch (Underscores)
+ {
+ case UnderscoreConvention.Prefix:
+ if (name.Length > 0 && name[0] != '_')
+ name = '_' + name;
+ break;
+ case UnderscoreConvention.Separate:
+ for (int i = 1; i < name.Length; ++i)
+ {
+ if (char.IsUpper(name[i])) {
+ name = name.Substring(0, i) + '_' +
name.Substring(i);
+ ++i;
+ }
+ }
+ break;
+ }

switch (Convention)
{
case NamingConvention.Pascal:
- SetName(property, char.ToUpper(name[0],
CultureInfo.InvariantCulture) + name.Substring(1)); break;
+ name = char.ToUpper(name[0],
CultureInfo.InvariantCulture) + name.Substring(1); break;
case NamingConvention.Camel:
- SetName(property, char.ToLower(name[0],
CultureInfo.InvariantCulture) + name.Substring(1)); break;
+ name = char.ToLower(name[0],
CultureInfo.InvariantCulture) + name.Substring(1); break;
case NamingConvention.Upper:
- SetName(property,
name.ToUpper(CultureInfo.InvariantCulture)); break;
+ name = name.ToUpper(CultureInfo.InvariantCulture);
break;
case NamingConvention.Lower:
- SetName(property,
name.ToLower(CultureInfo.InvariantCulture)); break;
- }
+ name = name.ToLower(CultureInfo.InvariantCulture);
break;
+ }
+
+ SetName(property, name);
}

private static void SetName(PropertyDescriptor property, string
name)
=======================================
---
/tests/Jayrock/Json/Conversion/TestJsonMemberNamingConventionAttribute.cs
Fri Apr 15 16:09:54 2011
+++
/tests/Jayrock/Json/Conversion/TestJsonMemberNamingConventionAttribute.cs
Sun Apr 17 16:27:53 2011
@@ -54,15 +54,29 @@
}

[ Test ]
- public void SetConvention()
- {
+ public void InitializeUnderscores()
+ {
+ JsonMemberNamingConventionAttribute attribute = new
JsonMemberNamingConventionAttribute(NamingConvention.Pascal,
UnderscoreConvention.Separate);
+ Assert.AreEqual(UnderscoreConvention.Separate,
attribute.Underscores);
+ }
+
+ [Test]
+ public void SetConvention() {
JsonMemberNamingConventionAttribute attribute = new
JsonMemberNamingConventionAttribute();
Assert.AreEqual(NamingConvention.None, attribute.Convention);
- attribute.Convention = NamingConvention.Pascal;
+ attribute.Convention = NamingConvention.Pascal;
Assert.AreEqual(NamingConvention.Pascal, attribute.Convention);
}

- [ Test ]
+ [Test]
+ public void SetUnderscores() {
+ JsonMemberNamingConventionAttribute attribute = new
JsonMemberNamingConventionAttribute();
+ Assert.AreEqual(UnderscoreConvention.None,
attribute.Underscores);
+ attribute.Underscores = UnderscoreConvention.Separate;
+ Assert.AreEqual(UnderscoreConvention.Separate,
attribute.Underscores);
+ }
+
+ [Test]
public void CustomizationSkippedWhenNoneConvention()
{
TestPropertyDescriptor property = CreateTestProperty("foo");
@@ -82,56 +96,72 @@
[ Test ]
public void PascalCaseApplication()
{
- TestNamingCase("pascalCase",
NamingConvention.Pascal, "PascalCase");
+ TestNamingCase("pascalCase", NamingConvention.Pascal,
UnderscoreConvention.None, "PascalCase");
}

[ Test ]
public void SingleLetterPascalCaseApplication()
{
- TestNamingCase("p", NamingConvention.Pascal, "P");
+ TestNamingCase("p", NamingConvention.Pascal,
UnderscoreConvention.None, "P");
}

[ Test ]
public void CamelCaseApplication()
{
- TestNamingCase("CamelCase",
NamingConvention.Camel, "camelCase");
- TestNamingCase("C", NamingConvention.Camel, "c");
+ TestNamingCase("CamelCase", NamingConvention.Camel,
UnderscoreConvention.None, "camelCase");
+ TestNamingCase("C", NamingConvention.Camel,
UnderscoreConvention.None, "c");
}

[ Test ]
public void SingleLetterCamelCaseApplication()
{
- TestNamingCase("C", NamingConvention.Camel, "c");
+ TestNamingCase("C", NamingConvention.Camel,
UnderscoreConvention.None, "c");
}

[ Test ]
public void UpperCaseApplication()
{
- TestNamingCase("upper", NamingConvention.Upper, "UPPER");
+ TestNamingCase("upper", NamingConvention.Upper,
UnderscoreConvention.None, "UPPER");
}

[ Test ]
- public void SinlgleLetterUpperCaseApplication()
- {
- TestNamingCase("u", NamingConvention.Upper, "U");
+ public void SingleLetterUpperCaseApplication()
+ {
+ TestNamingCase("u", NamingConvention.Upper,
UnderscoreConvention.None, "U");
}

[ Test ]
public void LowerCaseApplication()
{
- TestNamingCase("LOWER", NamingConvention.Lower, "lower");
+ TestNamingCase("LOWER", NamingConvention.Lower,
UnderscoreConvention.None, "lower");
}

[ Test ]
public void SingleLetterLowerCaseApplication()
{
- TestNamingCase("LOWER", NamingConvention.Lower, "lower");
- TestNamingCase("L", NamingConvention.Lower, "l");
+ TestNamingCase("LOWER", NamingConvention.Lower,
UnderscoreConvention.None, "lower");
+ TestNamingCase("L", NamingConvention.Lower,
UnderscoreConvention.None, "l");
}

- private static void TestNamingCase(string baseName,
NamingConvention testCase, string expected)
- {
- JsonMemberNamingConventionAttribute attribute = new
JsonMemberNamingConventionAttribute(testCase);
+ [Test]
+ public void UnderscorePrefixApplication() {
+ TestNamingCase("FooBarBaz", NamingConvention.Camel,
UnderscoreConvention.Prefix, "_FooBarBaz");
+ TestNamingCase("FooBarBaz", NamingConvention.Pascal,
UnderscoreConvention.Prefix, "_FooBarBaz");
+ TestNamingCase("FooBarBaz", NamingConvention.Upper,
UnderscoreConvention.Prefix, "_FOOBARBAZ");
+ TestNamingCase("FooBarBaz", NamingConvention.Lower,
UnderscoreConvention.Prefix, "_foobarbaz");
+ }
+
+ [Test]
+ public void UnderscoreSeparatorApplication() {
+ TestNamingCase("FooBarBaz", NamingConvention.Camel,
UnderscoreConvention.Separate, "foo_Bar_Baz");
+ TestNamingCase("FooBarBaz", NamingConvention.Pascal,
UnderscoreConvention.Separate, "Foo_Bar_Baz");
+ TestNamingCase("FooBarBaz", NamingConvention.Upper,
UnderscoreConvention.Separate, "FOO_BAR_BAZ");
+ TestNamingCase("FooBarBaz", NamingConvention.Lower,
UnderscoreConvention.Separate, "foo_bar_baz");
+ }
+
+ private static void TestNamingCase(string baseName,
NamingConvention testCase, UnderscoreConvention testUnder, string expected)
+ {
+ JsonMemberNamingConventionAttribute attribute = new
JsonMemberNamingConventionAttribute(testCase, testUnder);
TestPropertyDescriptor property = CreateTestProperty(baseName);
IPropertyDescriptorCustomization customization = attribute;


==============================================================================
Revision: e8c40fa10d52
Author: azizatif
Date: Mon Apr 18 14:27:45 2011
Log: Merged
http://code.google.com/p/jayrock/source/detail?r=e8c40fa10d52


Reply all
Reply to author
Forward
0 new messages