Skip to content

Commit

Permalink
Merge pull request #9 from hiddenswitch/unity5
Browse files Browse the repository at this point in the history
Unity 5 update
  • Loading branch information
doctorpangloss committed Jan 14, 2016
2 parents b6c0d90 + 664463f commit 8152564
Show file tree
Hide file tree
Showing 106 changed files with 6,528 additions and 6,478 deletions.
4 changes: 1 addition & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
[submodule "JsonFx"]
path = JsonFx
url = [email protected]:hiddenswitch/jsonfx-1.x.git

2 changes: 1 addition & 1 deletion Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Reflection;
using System.Collections;

namespace Extensions {
namespace Meteor.Extensions {
public static partial class ObjectExtensions
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace Extensions {
namespace Meteor.Extensions {
public static partial class StringExtensions
{
/// <summary>
Expand Down
1 change: 0 additions & 1 deletion JsonFx
Submodule JsonFx deleted from f1eb43
3 changes: 3 additions & 0 deletions JsonFx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store

.svn/
95 changes: 95 additions & 0 deletions JsonFx/DataReaderProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#region License
/*---------------------------------------------------------------------------------*\
Distributed under the terms of an MIT-style license:
The MIT License
Copyright (c) 2006-2009 Stephen M. McKamey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
\*---------------------------------------------------------------------------------*/
#endregion License

using System;
using System.Collections.Generic;

namespace JsonFx.Json
{
public interface IDataReaderProvider
{
IDataReader Find(string contentTypeHeader);
}

/// <summary>
/// Provides lookup capabilities for finding an IDataReader
/// </summary>
public class DataReaderProvider : IDataReaderProvider
{
#region Fields

private readonly IDictionary<string, IDataReader> ReadersByMime = new Dictionary<string, IDataReader>(StringComparer.OrdinalIgnoreCase);

#endregion Fields

#region Init

/// <summary>
/// Ctor
/// </summary>
/// <param name="readers">inject with all possible readers</param>
public DataReaderProvider(IEnumerable<IDataReader> readers)
{
if (readers != null)
{
foreach (IDataReader reader in readers)
{
if (!String.IsNullOrEmpty(reader.ContentType))
{
this.ReadersByMime[reader.ContentType] = reader;
}
}
}
}

#endregion Init

#region Methods

/// <summary>
/// Finds an IDataReader by content-type header
/// </summary>
/// <param name="contentTypeHeader"></param>
/// <returns></returns>
public IDataReader Find(string contentTypeHeader)
{
string type = DataWriterProvider.ParseMediaType(contentTypeHeader);

if (this.ReadersByMime.ContainsKey(type))
{
return ReadersByMime[type];
}

return null;
}

#endregion Methods
}
}
2 changes: 1 addition & 1 deletion SRP/Crypto.cs.meta → JsonFx/DataReaderProvider.cs.meta
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

219 changes: 219 additions & 0 deletions JsonFx/DataWriterProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
#region License
/*---------------------------------------------------------------------------------*\
Distributed under the terms of an MIT-style license:
The MIT License
Copyright (c) 2006-2009 Stephen M. McKamey
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
\*---------------------------------------------------------------------------------*/
#endregion License

using System;
using System.Collections.Generic;
using System.IO;

namespace JsonFx.Json
{
public interface IDataWriterProvider
{
IDataWriter DefaultDataWriter { get; }

IDataWriter Find(string extension);

IDataWriter Find(string acceptHeader, string contentTypeHeader);
}

/// <summary>
/// Provides lookup capabilities for finding an IDataWriter
/// </summary>
public class DataWriterProvider : IDataWriterProvider
{
#region Fields

private readonly IDataWriter DefaultWriter;
private readonly IDictionary<string, IDataWriter> WritersByExt = new Dictionary<string, IDataWriter>(StringComparer.OrdinalIgnoreCase);
private readonly IDictionary<string, IDataWriter> WritersByMime = new Dictionary<string, IDataWriter>(StringComparer.OrdinalIgnoreCase);

#endregion Fields

#region Init

/// <summary>
/// Ctor
/// </summary>
/// <param name="writers">inject with all possible writers</param>
public DataWriterProvider(IEnumerable<IDataWriter> writers)
{
if (writers != null)
{
foreach (IDataWriter writer in writers)
{
if (this.DefaultWriter == null)
{
// TODO: decide less arbitrary way to choose default
// without hardcoding value into IDataWriter
this.DefaultWriter = writer;
}

if (!String.IsNullOrEmpty(writer.ContentType))
{
this.WritersByMime[writer.ContentType] = writer;
}

if (!String.IsNullOrEmpty(writer.ContentType))
{
string ext = DataWriterProvider.NormalizeExtension(writer.FileExtension);
this.WritersByExt[ext] = writer;
}
}
}
}

#endregion Init

#region Properties

public IDataWriter DefaultDataWriter
{
get { return this.DefaultWriter; }
}

#endregion Properties

#region Methods

public IDataWriter Find(string extension)
{
extension = DataWriterProvider.NormalizeExtension(extension);

if (this.WritersByExt.ContainsKey(extension))
{
return WritersByExt[extension];
}

return null;
}

public IDataWriter Find(string acceptHeader, string contentTypeHeader)
{
foreach (string type in DataWriterProvider.ParseHeaders(acceptHeader, contentTypeHeader))
{
if (this.WritersByMime.ContainsKey(type))
{
return WritersByMime[type];
}
}

return null;
}

#endregion Methods

#region Utility Methods

/// <summary>
/// Parses HTTP headers for Media-Types
/// </summary>
/// <param name="accept">HTTP Accept header</param>
/// <param name="contentType">HTTP Content-Type header</param>
/// <returns>sequence of Media-Types</returns>
/// <remarks>
/// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
/// </remarks>
public static IEnumerable<string> ParseHeaders(string accept, string contentType)
{
string mime;

// check for a matching accept type
foreach (string type in DataWriterProvider.SplitTrim(accept, ','))
{
mime = DataWriterProvider.ParseMediaType(type);
if (!String.IsNullOrEmpty(mime))
{
yield return mime;
}
}

// fallback on content-type
mime = DataWriterProvider.ParseMediaType(contentType);
if (!String.IsNullOrEmpty(mime))
{
yield return mime;
}
}

/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static string ParseMediaType(string type)
{
foreach (string mime in DataWriterProvider.SplitTrim(type, ';'))
{
// only return first part
return mime;
}

// if no parts then was empty
return String.Empty;
}

private static IEnumerable<string> SplitTrim(string source, char ch)
{
if (String.IsNullOrEmpty(source))
{
yield break;
}

int length = source.Length;
for (int prev=0, next=0; prev<length && next>=0; prev=next+1)
{
next = source.IndexOf(ch, prev);
if (next < 0)
{
next = length;
}

string part = source.Substring(prev, next-prev).Trim();
if (part.Length > 0)
{
yield return part;
}
}
}

private static string NormalizeExtension(string extension)
{
if (String.IsNullOrEmpty(extension))
{
return String.Empty;
}

// ensure is only extension with leading dot
return Path.GetExtension(extension);
}

#endregion Utility Methods
}
}
2 changes: 1 addition & 1 deletion SRP/SHA256.cs.meta → JsonFx/DataWriterProvider.cs.meta
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8152564

Please sign in to comment.