-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reintroduce Tavis.UriTemplates which had been upgraded to netstandard…
… 2.1 in 2022.
- Loading branch information
1 parent
418c91a
commit 4c6c650
Showing
8 changed files
with
898 additions
and
894 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
namespace Tavis.UriTemplates | ||
{ | ||
public class OperatorInfo | ||
{ | ||
public bool Default { get; set; } | ||
public string First { get; set; } | ||
public char Separator { get; set; } | ||
public bool Named { get; set; } | ||
public string IfEmpty { get; set; } | ||
public bool AllowReserved { get; set; } | ||
//namespace Tavis.UriTemplates | ||
//{ | ||
// public class OperatorInfo | ||
// { | ||
// public bool Default { get; set; } | ||
// public string First { get; set; } | ||
// public char Separator { get; set; } | ||
// public bool Named { get; set; } | ||
// public string IfEmpty { get; set; } | ||
// public bool AllowReserved { get; set; } | ||
|
||
} | ||
} | ||
// } | ||
//} |
16 changes: 8 additions & 8 deletions
16
Fonlow.Web.MetaCore/UriTemplatesCore/QueryStringParameterOrder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
namespace Tavis.UriTemplates | ||
{ | ||
public enum QueryStringParameterOrder | ||
{ | ||
Strict, | ||
Any | ||
} | ||
} | ||
//namespace Tavis.UriTemplates | ||
//{ | ||
// public enum QueryStringParameterOrder | ||
// { | ||
// Strict, | ||
// Any | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,149 +1,149 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Tavis.UriTemplates | ||
{ | ||
public class Result | ||
{ | ||
public bool ErrorDetected { get; set; } | ||
public IList<string> ParameterNames {get;} | ||
private const string _UriReservedSymbols = ":/?#[]@!$&'()*+,;="; | ||
private const string _UriUnreservedSymbols = "-._~"; | ||
|
||
private StringBuilder _Result = new StringBuilder(); | ||
|
||
public Result() | ||
{ | ||
ParameterNames = new List<string>(); | ||
} | ||
public StringBuilder Append(char value) | ||
{ | ||
return _Result.Append(value); | ||
} | ||
public StringBuilder Append(string value) | ||
{ | ||
|
||
return _Result.Append(value); | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return _Result.ToString(); | ||
} | ||
public void AppendName(string variable, OperatorInfo op, bool valueIsEmpty) | ||
{ | ||
_Result.Append(variable); | ||
if (valueIsEmpty) { _Result.Append(op.IfEmpty); } else { _Result.Append('='); } | ||
} | ||
|
||
|
||
public void AppendList(OperatorInfo op, bool explode, string variable, IList list) | ||
{ | ||
foreach (object item in list) | ||
{ | ||
if (op.Named && explode) | ||
{ | ||
_Result.Append(variable); | ||
_Result.Append('='); | ||
} | ||
AppendValue(item.ToString(), 0, op.AllowReserved); | ||
|
||
_Result.Append(explode ? op.Separator : ','); | ||
} | ||
if (list.Count > 0) | ||
{ | ||
_Result.Remove(_Result.Length - 1, 1); | ||
} | ||
} | ||
|
||
public void AppendDictionary(OperatorInfo op, bool explode, IDictionary<string, string> dictionary) | ||
{ | ||
foreach (string key in dictionary.Keys) | ||
{ | ||
_Result.Append(Encode(key, op.AllowReserved)); | ||
if (explode) _Result.Append('='); else _Result.Append(','); | ||
AppendValue(dictionary[key], 0, op.AllowReserved); | ||
|
||
if (explode) | ||
{ | ||
_Result.Append(op.Separator); | ||
} | ||
else | ||
{ | ||
_Result.Append(','); | ||
} | ||
} | ||
if (dictionary.Count > 0) | ||
{ | ||
_Result.Remove(_Result.Length - 1, 1); | ||
} | ||
} | ||
|
||
public void AppendValue(string value, int prefixLength, bool allowReserved) | ||
{ | ||
|
||
if (prefixLength != 0) | ||
{ | ||
if (prefixLength < value.Length) | ||
{ | ||
value = value.Substring(0, prefixLength); | ||
} | ||
} | ||
|
||
_Result.Append(Encode(value, allowReserved)); | ||
|
||
} | ||
//using System.Collections; | ||
//using System.Collections.Generic; | ||
//using System.Linq; | ||
//using System.Text; | ||
|
||
//namespace Tavis.UriTemplates | ||
//{ | ||
// public class Result | ||
// { | ||
// public bool ErrorDetected { get; set; } | ||
// public IList<string> ParameterNames {get;} | ||
// private const string _UriReservedSymbols = ":/?#[]@!$&'()*+,;="; | ||
// private const string _UriUnreservedSymbols = "-._~"; | ||
|
||
// private StringBuilder _Result = new StringBuilder(); | ||
|
||
// public Result() | ||
// { | ||
// ParameterNames = new List<string>(); | ||
// } | ||
// public StringBuilder Append(char value) | ||
// { | ||
// return _Result.Append(value); | ||
// } | ||
// public StringBuilder Append(string value) | ||
// { | ||
|
||
// return _Result.Append(value); | ||
// } | ||
|
||
// public override string ToString() | ||
// { | ||
// return _Result.ToString(); | ||
// } | ||
// public void AppendName(string variable, OperatorInfo op, bool valueIsEmpty) | ||
// { | ||
// _Result.Append(variable); | ||
// if (valueIsEmpty) { _Result.Append(op.IfEmpty); } else { _Result.Append('='); } | ||
// } | ||
|
||
|
||
// public void AppendList(OperatorInfo op, bool explode, string variable, IList list) | ||
// { | ||
// foreach (object item in list) | ||
// { | ||
// if (op.Named && explode) | ||
// { | ||
// _Result.Append(variable); | ||
// _Result.Append('='); | ||
// } | ||
// AppendValue(item.ToString(), 0, op.AllowReserved); | ||
|
||
// _Result.Append(explode ? op.Separator : ','); | ||
// } | ||
// if (list.Count > 0) | ||
// { | ||
// _Result.Remove(_Result.Length - 1, 1); | ||
// } | ||
// } | ||
|
||
// public void AppendDictionary(OperatorInfo op, bool explode, IDictionary<string, string> dictionary) | ||
// { | ||
// foreach (string key in dictionary.Keys) | ||
// { | ||
// _Result.Append(Encode(key, op.AllowReserved)); | ||
// if (explode) _Result.Append('='); else _Result.Append(','); | ||
// AppendValue(dictionary[key], 0, op.AllowReserved); | ||
|
||
// if (explode) | ||
// { | ||
// _Result.Append(op.Separator); | ||
// } | ||
// else | ||
// { | ||
// _Result.Append(','); | ||
// } | ||
// } | ||
// if (dictionary.Count > 0) | ||
// { | ||
// _Result.Remove(_Result.Length - 1, 1); | ||
// } | ||
// } | ||
|
||
// public void AppendValue(string value, int prefixLength, bool allowReserved) | ||
// { | ||
|
||
// if (prefixLength != 0) | ||
// { | ||
// if (prefixLength < value.Length) | ||
// { | ||
// value = value.Substring(0, prefixLength); | ||
// } | ||
// } | ||
|
||
// _Result.Append(Encode(value, allowReserved)); | ||
|
||
// } | ||
|
||
|
||
private static string Encode(string p, bool allowReserved) | ||
{ | ||
|
||
StringBuilder result = new StringBuilder(); | ||
foreach (char c in p) | ||
{ | ||
if ((c >= 'A' && c <= 'z') //Alpha | ||
|| (c >= '0' && c <= '9') // Digit | ||
|| _UriUnreservedSymbols.Contains(c) // Unreserved symbols - These should never be percent encoded | ||
|| (allowReserved && _UriReservedSymbols.Contains(c))) // Reserved symbols - should be included if requested (+) | ||
{ | ||
result.Append(c); | ||
} | ||
else | ||
{ | ||
byte[] bytes = Encoding.UTF8.GetBytes(new []{c}); | ||
foreach (byte abyte in bytes) | ||
{ | ||
result.Append(HexEscape(abyte)); | ||
} | ||
|
||
} | ||
} | ||
|
||
return result.ToString(); | ||
|
||
|
||
} | ||
|
||
public static string HexEscape(byte i) | ||
{ | ||
char[] esc = new char[3]; | ||
esc[0] = '%'; | ||
esc[1] = HexDigits[((i & 240) >> 4)]; | ||
esc[2] = HexDigits[(i & 15)]; | ||
return new string(esc); | ||
} | ||
public static string HexEscape(char c) { | ||
char[] esc = new char[3]; | ||
esc[0] = '%'; | ||
esc[1] = HexDigits[(((int) c & 240) >> 4)]; | ||
esc[2] = HexDigits[((int) c & 15)]; | ||
return new string(esc); | ||
} | ||
private static readonly char[] HexDigits = new char[] {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; | ||
|
||
|
||
|
||
} | ||
} | ||
// private static string Encode(string p, bool allowReserved) | ||
// { | ||
|
||
// StringBuilder result = new StringBuilder(); | ||
// foreach (char c in p) | ||
// { | ||
// if ((c >= 'A' && c <= 'z') //Alpha | ||
// || (c >= '0' && c <= '9') // Digit | ||
// || _UriUnreservedSymbols.Contains(c) // Unreserved symbols - These should never be percent encoded | ||
// || (allowReserved && _UriReservedSymbols.Contains(c))) // Reserved symbols - should be included if requested (+) | ||
// { | ||
// result.Append(c); | ||
// } | ||
// else | ||
// { | ||
// byte[] bytes = Encoding.UTF8.GetBytes(new []{c}); | ||
// foreach (byte abyte in bytes) | ||
// { | ||
// result.Append(HexEscape(abyte)); | ||
// } | ||
|
||
// } | ||
// } | ||
|
||
// return result.ToString(); | ||
|
||
|
||
// } | ||
|
||
// public static string HexEscape(byte i) | ||
// { | ||
// char[] esc = new char[3]; | ||
// esc[0] = '%'; | ||
// esc[1] = HexDigits[((i & 240) >> 4)]; | ||
// esc[2] = HexDigits[(i & 15)]; | ||
// return new string(esc); | ||
// } | ||
// public static string HexEscape(char c) { | ||
// char[] esc = new char[3]; | ||
// esc[0] = '%'; | ||
// esc[1] = HexDigits[(((int) c & 240) >> 4)]; | ||
// esc[2] = HexDigits[((int) c & 15)]; | ||
// return new string(esc); | ||
// } | ||
// private static readonly char[] HexDigits = new char[] {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; | ||
|
||
|
||
|
||
// } | ||
//} |
Oops, something went wrong.