/CSV.cs |
@@ -25,7 +25,7 @@ |
return string.Join(",", |
input |
.Select(o => o.Replace("\"", "\"\"")) |
.Select(o => o.IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1) ? o : "\"" + o + "\"")); |
.Select(o => o.IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1) ? o : "\"" + o + "\"")); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -41,10 +41,10 @@ |
return string.Join(",", input.Keys.Select(o => o.ToString()).Zip(input.Values.Select(o => o.ToString()), |
(o, p) => |
string.Join(",", |
o.Replace("\"", "\"\"").IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1) |
o.Replace("\"", "\"\"").IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1) |
? o |
: "\"" + o + "\"", |
p.Replace("\"", "\"\"").IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1) |
p.Replace("\"", "\"\"").IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1) |
? p |
: "\"" + p + "\""))); |
} |
@@ -58,10 +58,10 @@ |
/// <returns>key-value pairs of successive comma-separate values</returns> |
public static IEnumerable<KeyValuePair<string, string>> ToKeyValue(string input) |
{ |
return ToEnumerable(input).AsParallel().Select((o, p) => new {o, p}) |
.GroupBy(q => q.p/2, q => q.o) |
return ToEnumerable(input).AsParallel().Select((o, p) => new { o, p }) |
.GroupBy(q => q.p / 2, q => q.o) |
.Select(o => o.ToArray()) |
.TakeWhile(o => o.Length%2 == 0) |
.TakeWhile(o => o.Length % 2 == 0) |
.Where(o => !string.IsNullOrEmpty(o[0]) || !string.IsNullOrEmpty(o[1])) |
.ToDictionary(o => o[0], p => p[1]).Select(o => o); |
} |
@@ -80,11 +80,11 @@ |
var value = input.Value.ToString(); |
|
return string.Join(",", key |
.Replace("\"", "\"\"").IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}).Equals(-1) |
.Replace("\"", "\"\"").IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }).Equals(-1) |
? key |
: "\"" + key + "\"", value |
.Replace("\"", "\"\"") |
.IndexOfAny(new[] {'"', ' ', ',', '\r', '\n'}) |
.IndexOfAny(new[] { '"', ' ', ',', '\r', '\n' }) |
.Equals(-1) |
? value |
: "\"" + value + "\""); |
@@ -137,4 +137,4 @@ |
yield return m.ToString(); |
} |
} |
} |
} |
/Collections/Generic/SerializableDictionary.cs |
@@ -39,11 +39,11 @@ |
reader.ReadStartElement(ItemNodeName); |
|
reader.ReadStartElement(KeyNodeName); |
var key = (TKey) KeySerializer.Deserialize(reader); |
var key = (TKey)KeySerializer.Deserialize(reader); |
reader.ReadEndElement(); |
|
reader.ReadStartElement(ValueNodeName); |
var value = (TValue) ValueSerializer.Deserialize(reader); |
var value = (TValue)ValueSerializer.Deserialize(reader); |
reader.ReadEndElement(); |
|
Add(key, value); |
@@ -93,7 +93,7 @@ |
.Deserialize(memoryStream); |
} |
} |
/* cloning failed so return an empty dictionary */ |
/* cloning failed so return an empty dictionary */ |
catch (Exception) |
{ |
clone = new SerializableDictionary<TKey, TValue>(); |
@@ -108,7 +108,7 @@ |
public string KeyNodeName { get; set; } = "Key"; |
public string ValueNodeName { get; set; } = "Value"; |
|
#endregion |
#endregion Constants |
|
#region Constructors |
|
@@ -141,7 +141,7 @@ |
{ |
} |
|
#endregion |
#endregion Constructors |
|
#region Private Properties |
|
@@ -150,7 +150,7 @@ |
|
private XmlSerializer KeySerializer => keySerializer ?? (keySerializer = new XmlSerializer(typeof(TKey))); |
|
#endregion |
#endregion Private Properties |
|
#region Private Members |
|
@@ -157,6 +157,6 @@ |
private XmlSerializer keySerializer; |
private XmlSerializer valueSerializer; |
|
#endregion |
#endregion Private Members |
} |
} |
} |
/Collections/Specialized/ObservableDictionary.cs |
@@ -41,7 +41,7 @@ |
|
public void Add(KeyValuePair<K, V> item) |
{ |
((IDictionary<K, V>) store).Add(item); |
((IDictionary<K, V>)store).Add(item); |
IsVirgin = false; |
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item)); |
} |
@@ -64,7 +64,7 @@ |
|
public bool Contains(KeyValuePair<K, V> item) |
{ |
return ((IDictionary<K, V>) store).Contains(item); |
return ((IDictionary<K, V>)store).Contains(item); |
} |
|
public bool ContainsKey(K key) |
@@ -74,17 +74,17 @@ |
|
public void CopyTo(KeyValuePair<K, V>[] array, int arrayIndex) |
{ |
((IDictionary<K, V>) store).CopyTo(array, arrayIndex); |
((IDictionary<K, V>)store).CopyTo(array, arrayIndex); |
} |
|
public IEnumerator<KeyValuePair<K, V>> GetEnumerator() |
{ |
return ((IDictionary<K, V>) store).GetEnumerator(); |
return ((IDictionary<K, V>)store).GetEnumerator(); |
} |
|
public bool Remove(KeyValuePair<K, V> item) |
{ |
var removed = ((IDictionary<K, V>) store).Remove(item); |
var removed = ((IDictionary<K, V>)store).Remove(item); |
IsVirgin = false; |
if (removed) |
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item)); |
@@ -111,7 +111,7 @@ |
|
IEnumerator IEnumerable.GetEnumerator() |
{ |
return ((IDictionary<K, V>) store).GetEnumerator(); |
return ((IDictionary<K, V>)store).GetEnumerator(); |
} |
|
public event NotifyCollectionChangedEventHandler CollectionChanged; |
@@ -121,4 +121,4 @@ |
CollectionChanged?.Invoke(this, args); |
} |
} |
} |
} |
/Cryptography.cs |
@@ -187,7 +187,7 @@ |
var plug = plugs[Array.IndexOf(rotors, rotor)]; |
var i = Array.IndexOf(def_rotors[rotor], plug); |
if (i.Equals(0)) continue; |
def_rotors[rotor] = Arrays.ConcatenateArrays(new[] {plug}, |
def_rotors[rotor] = Arrays.ConcatenateArrays(new[] { plug }, |
Arrays.GetSubArray(Arrays.DeleteSubArray(def_rotors[rotor], i, i), i, -1), |
Arrays.GetSubArray(Arrays.DeleteSubArray(def_rotors[rotor], i + 1, -1), 0, i - 1)); |
} |
@@ -225,7 +225,7 @@ |
|
// Reflect |
var x = Array.IndexOf(def_reflectors[reflector], l); |
l = (x + 1)%2 == 0 ? def_reflectors[reflector][x - 1] : def_reflectors[reflector][x + 1]; |
l = (x + 1) % 2 == 0 ? def_reflectors[reflector][x - 1] : def_reflectors[reflector][x + 1]; |
|
// Reverse the order of the rotors. |
Array.Reverse(rotors); |
@@ -265,7 +265,7 @@ |
++i; |
continue; |
} |
var m = j%enc_key.Length; |
var m = j % enc_key.Length; |
exp_key += enc_key[m]; |
++j; |
++i; |
@@ -392,4 +392,4 @@ |
return new string(input); |
} |
} |
} |
} |
/Geo/GeodesicExtensions.cs |
@@ -20,19 +20,18 @@ |
GeographicCoordinate targetGeographicCoordinate, |
DistanceUnits distanceUnits) |
{ |
var sourcePhi = Math.PI*sourceGeographicCoordinate.Latitude/180; |
var targetPhi = Math.PI*targetGeographicCoordinate.Latitude/180; |
var deltaPhi = Math.PI*(targetPhi - sourcePhi)/180; |
var deltaLam = Math.PI*(targetGeographicCoordinate.Longitude - sourceGeographicCoordinate.Longitude)/180; |
var sourcePhi = Math.PI * sourceGeographicCoordinate.Latitude / 180; |
var targetPhi = Math.PI * targetGeographicCoordinate.Latitude / 180; |
var deltaPhi = Math.PI * (targetPhi - sourcePhi) / 180; |
var deltaLam = Math.PI * (targetGeographicCoordinate.Longitude - sourceGeographicCoordinate.Longitude) / 180; |
|
var a = Math.Sin(deltaPhi / 2) * Math.Sin(deltaPhi / 2) + |
Math.Cos(sourcePhi) * Math.Cos(targetPhi) * |
Math.Sin(deltaLam / 2) * Math.Sin(deltaLam / 2); |
|
var a = Math.Sin(deltaPhi/2)*Math.Sin(deltaPhi/2) + |
Math.Cos(sourcePhi)*Math.Cos(targetPhi)* |
Math.Sin(deltaLam/2)*Math.Sin(deltaLam/2); |
var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); |
|
var c = 2*Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); |
|
return new Distance(Constants.EARTH_MEAN_RADIUS.Meters*c); |
return new Distance(Constants.EARTH_MEAN_RADIUS.Meters * c); |
} |
} |
} |
} |
/KeyValue.cs |
@@ -24,7 +24,7 @@ |
return data.Split('&') |
.AsParallel() |
.Select(o => o.Split('=')) |
.Where(o => o.Length.Equals(2) && String.Equals(o[0], key, StringComparison.Ordinal)) |
.Where(o => o.Length.Equals(2) && string.Equals(o[0], key, StringComparison.Ordinal)) |
.Select(o => o[1]) |
.FirstOrDefault(); |
} |
@@ -44,7 +44,7 @@ |
return string.Join("&", string.Join("&", data.Split('&') |
.AsParallel() |
.Select(o => o.Split('=')) |
.Where(o => o.Length.Equals(2) && !String.Equals(o[0], key, StringComparison.Ordinal)) |
.Where(o => o.Length.Equals(2) && !string.Equals(o[0], key, StringComparison.Ordinal)) |
.Select(o => string.Join("=", o[0], o[1]))), string.Join("=", key, value)); |
} |
|
@@ -60,7 +60,7 @@ |
return string.Join("&", data.Split('&') |
.AsParallel() |
.Select(o => o.Split('=')) |
.Where(o => o.Length.Equals(2) && !String.Equals(o[0], key, StringComparison.Ordinal)) |
.Where(o => o.Length.Equals(2) && !string.Equals(o[0], key, StringComparison.Ordinal)) |
.Select(o => string.Join("=", o[0], o[1]))); |
} |
|
@@ -122,4 +122,4 @@ |
return data.AsParallel().ToDictionary(o => func(o.Key), p => func(p.Value)); |
} |
} |
} |
} |
/Properties/AssemblyInfo.cs |
@@ -1,7 +1,7 @@ |
using System.Reflection; |
using System.Resources; |
|
// General Information about an assembly is controlled through the following |
// General Information about an assembly is controlled through the following |
// set of attributes. Change these attribute values to modify the information |
// associated with an assembly. |
|
@@ -18,12 +18,12 @@ |
// Version information for an assembly consists of the following four values: |
// |
// Major Version |
// Minor Version |
// Minor Version |
// Build Number |
// Revision |
// |
// You can specify all the values or you can default the Build and Revision Numbers |
// You can specify all the values or you can default the Build and Revision Numbers |
// by using the '*' as shown below: |
// [assembly: AssemblyVersion("1.0.*")] |
|
[assembly: AssemblyVersion("1.41.*")] |
[assembly: AssemblyVersion("1.42.*")] |
/Reflection.cs |
@@ -22,7 +22,7 @@ |
/// <returns>an attribute of type T</returns> |
public static T GetAttributeFromEnumValue<T>(Enum value) where T : Attribute |
{ |
return (T) value.GetType() |
return (T)value.GetType() |
.GetRuntimeField(value.ToString()) |
.GetCustomAttributes(typeof(T), false) |
.SingleOrDefault(); |
@@ -40,7 +40,7 @@ |
{ |
return e.GetType().GetRuntimeFields().ToArray() |
.AsParallel() |
.Select(o => GetAttributeFromEnumValue<T>((Enum) o.GetValue(Activator.CreateInstance<T>()))); |
.Select(o => GetAttributeFromEnumValue<T>((Enum)o.GetValue(Activator.CreateInstance<T>()))); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -70,7 +70,7 @@ |
/// <returns>the values of the enumeration</returns> |
public static IEnumerable<T> GetEnumValues<T>() |
{ |
return Enum.GetValues(typeof(T)).Cast<object>().Select(value => (T) value); |
return Enum.GetValues(typeof(T)).Cast<object>().Select(value => (T)value); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -123,10 +123,10 @@ |
var field = typeof(T).GetRuntimeFields().ToArray() |
.AsParallel().SelectMany(f => f.GetCustomAttributes( |
typeof(NameAttribute), false), ( |
f, a) => new {Field = f, Att = a}) |
.SingleOrDefault(a => String.Equals(((NameAttribute) a.Att) |
f, a) => new { Field = f, Att = a }) |
.SingleOrDefault(a => string.Equals(((NameAttribute)a.Att) |
.Name, name, comparison)); |
return field != null ? (T) field.Field.GetValue(Activator.CreateInstance<T>()) : default(T); |
return field != null ? (T)field.Field.GetValue(Activator.CreateInstance<T>()) : default(T); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -143,8 +143,8 @@ |
{ |
var field = typeof(T).GetRuntimeFields().ToArray() |
.AsParallel().SelectMany(f => f.GetCustomAttributes(typeof(NameAttribute), false), |
(f, a) => new {Field = f, Att = a}).SingleOrDefault(f => f.Field.GetValue(structure).Equals(item)); |
return field != null ? ((NameAttribute) field.Att).Name : string.Empty; |
(f, a) => new { Field = f, Att = a }).SingleOrDefault(f => f.Field.GetValue(structure).Equals(item)); |
return field != null ? ((NameAttribute)field.Att).Name : string.Empty; |
} |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -285,4 +285,4 @@ |
public string Description => description; |
} |
} |
} |
} |
/Strings.cs |
@@ -4,7 +4,6 @@ |
// rights of fair usage, the disclaimer and warranty conditions. // |
/////////////////////////////////////////////////////////////////////////// |
|
using System; |
using System.IO; |
using System.Linq; |
|
@@ -24,34 +23,5 @@ |
{ |
return paths.Aggregate((x, y) => Path.Combine(x, y)); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary> |
/// Determines if two strings are equal. |
/// </summary> |
/// <param name="a">first string</param> |
/// <param name="b">second string</param> |
/// <param name="comparison">string comparison to use</param> |
/// <returns>true if the strings are equal</returns> |
public static bool Equals(string a, string b, StringComparison comparison) |
{ |
return (a == null && b == null) || (a.Length == b.Length && string.Equals(a, b, comparison)); |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2016 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
/// <summary> |
/// Determines if two strings are equal. |
/// </summary> |
/// <param name="a">first string</param> |
/// <param name="b">second string</param> |
/// <returns>true if the strings are equal</returns> |
public static bool Equals(string a, string b) |
{ |
return (a == null && b == null) || (a != null && b != null && a.Length == b.Length && string.Equals(a, b)); |
} |
} |
} |
} |
/Timers/DecayingAlarm.cs |
@@ -28,11 +28,25 @@ |
[Flags] |
public enum DECAY_TYPE |
{ |
[Reflection.NameAttribute("none")] [XmlEnum(Name = "none")] NONE = 0, |
[Reflection.NameAttribute("arithmetic")] [XmlEnum(Name = "arithmetic")] ARITHMETIC = 1, |
[Reflection.NameAttribute("geometric")] [XmlEnum(Name = "geometric")] GEOMETRIC = 2, |
[Reflection.NameAttribute("harmonic")] [XmlEnum(Name = "harmonic")] HARMONIC = 4, |
[Reflection.NameAttribute("weighted")] [XmlEnum(Name = "weighted")] WEIGHTED = 5 |
[Reflection.NameAttribute("none")] |
[XmlEnum(Name = "none")] |
NONE = 0, |
|
[Reflection.NameAttribute("arithmetic")] |
[XmlEnum(Name = "arithmetic")] |
ARITHMETIC = 1, |
|
[Reflection.NameAttribute("geometric")] |
[XmlEnum(Name = "geometric")] |
GEOMETRIC = 2, |
|
[Reflection.NameAttribute("harmonic")] |
[XmlEnum(Name = "harmonic")] |
HARMONIC = 4, |
|
[Reflection.NameAttribute("weighted")] |
[XmlEnum(Name = "weighted")] |
WEIGHTED = 5 |
} |
|
private readonly DECAY_TYPE decay = DECAY_TYPE.NONE; |
@@ -92,6 +106,7 @@ |
} |
}, deadline, 0); |
return; |
|
case false: |
elapsed.Stop(); |
times.Add(elapsed.ElapsedMilliseconds); |
@@ -99,24 +114,28 @@ |
{ |
case DECAY_TYPE.ARITHMETIC: |
alarm?.Change( |
(int) ((deadline + times.Aggregate((a, b) => b + a))/(1f + times.Count)), 0); |
(int)((deadline + times.Aggregate((a, b) => b + a)) / (1f + times.Count)), 0); |
break; |
|
case DECAY_TYPE.GEOMETRIC: |
alarm?.Change((int) Math.Pow(deadline*times.Aggregate((a, b) => b*a), |
1f/(1f + times.Count)), 0); |
alarm?.Change((int)Math.Pow(deadline * times.Aggregate((a, b) => b * a), |
1f / (1f + times.Count)), 0); |
break; |
|
case DECAY_TYPE.HARMONIC: |
alarm?.Change((int) ((1f + times.Count)/ |
(1f/deadline + times.Aggregate((a, b) => 1f/b + 1f/a))), 0); |
alarm?.Change((int)((1f + times.Count) / |
(1f / deadline + times.Aggregate((a, b) => 1f / b + 1f / a))), 0); |
break; |
|
case DECAY_TYPE.WEIGHTED: |
var d = new HashSet<double>(times) {deadline}; |
var d = new HashSet<double>(times) { deadline }; |
var total = d.Aggregate((a, b) => b + a); |
alarm?.Change( |
(int) d.Aggregate((a, b) => Math.Pow(a, 2)/total + Math.Pow(b, 2)/total), 0); |
(int)d.Aggregate((a, b) => Math.Pow(a, 2) / total + Math.Pow(b, 2) / total), 0); |
break; |
|
default: |
alarm?.Change((int) deadline, 0); |
alarm?.Change((int)deadline, 0); |
break; |
} |
elapsed.Reset(); |
@@ -140,4 +159,4 @@ |
return new DecayingAlarm(decay); |
} |
} |
} |
} |
/Web/QValueParsing.cs |
@@ -1,18 +1,18 @@ |
// The MIT License (MIT) |
// |
// |
// Copyright (c) 2015 Dave Transom |
// |
// |
// Permission is hereby granted, free of charge, to any person obtaining a |
// copy of this software and associated documentation files (the |
// 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. |
@@ -48,7 +48,7 @@ |
[DebuggerDisplay("QValue[{Name}, {Weight}]")] |
public struct QValue : IComparable<QValue> |
{ |
private static readonly char[] delimiters = {';', '='}; |
private static readonly char[] delimiters = { ';', '=' }; |
private const float defaultWeight = 1; |
|
#region Fields |
@@ -56,7 +56,7 @@ |
private float _weight; |
private int _ordinal; |
|
#endregion |
#endregion Fields |
|
#region Constructors |
|
@@ -89,7 +89,7 @@ |
ParseInternal(ref this, value); |
} |
|
#endregion |
#endregion Constructors |
|
#region Properties |
|
@@ -114,7 +114,7 @@ |
/// </summary> |
public bool IsEmpty => string.IsNullOrEmpty(Name); |
|
#endregion |
#endregion Properties |
|
#region Methods |
|
@@ -165,7 +165,7 @@ |
} |
} |
|
#endregion |
#endregion Methods |
|
#region IComparable<QValue> Members |
|
@@ -186,7 +186,7 @@ |
return value; |
} |
|
#endregion |
#endregion IComparable<QValue> Members |
|
#region CompareByWeight |
|
@@ -212,7 +212,7 @@ |
return -x.CompareTo(y); |
} |
|
#endregion |
#endregion CompareByWeight |
} |
|
/// <summary> |
@@ -225,7 +225,7 @@ |
[DebuggerDisplay("QValue[{Count}, {AcceptWildcard}]")] |
public sealed class QValueList : List<QValue> |
{ |
private static readonly char[] delimiters = {','}; |
private static readonly char[] delimiters = { ',' }; |
|
#region Add |
|
@@ -241,7 +241,7 @@ |
applyAutoSort(); |
} |
|
#endregion |
#endregion Add |
|
#region AddRange |
|
@@ -261,7 +261,7 @@ |
applyAutoSort(); |
} |
|
#endregion |
#endregion AddRange |
|
#region Find |
|
@@ -277,7 +277,7 @@ |
return Find(criteria); |
} |
|
#endregion |
#endregion Find |
|
#region FindHighestWeight |
|
@@ -297,7 +297,7 @@ |
return Find(criteria); |
} |
|
#endregion |
#endregion FindHighestWeight |
|
#region FindPreferred |
|
@@ -318,7 +318,7 @@ |
return Find(criteria); |
} |
|
#endregion |
#endregion FindPreferred |
|
#region DefaultSort |
|
@@ -331,7 +331,7 @@ |
Sort(QValue.CompareByWeightDesc); |
} |
|
#endregion |
#endregion DefaultSort |
|
#region applyAutoSort |
|
@@ -345,7 +345,7 @@ |
DefaultSort(); |
} |
|
#endregion |
#endregion applyAutoSort |
|
#region isCandidate |
|
@@ -366,12 +366,8 @@ |
return false; |
} |
|
#endregion |
#endregion isCandidate |
|
#region Fields |
|
#endregion |
|
#region Constructors |
|
/// <summary> |
@@ -413,7 +409,7 @@ |
AutoSort = true; |
} |
|
#endregion |
#endregion Constructors |
|
#region Properties |
|
@@ -434,6 +430,6 @@ |
/// <returns>An QValue based on weight, or null</returns> |
public QValue this[params string[] candidates] => FindPreferred(candidates); |
|
#endregion |
#endregion Properties |
} |
} |
} |
/Web/Utilities/WebExtensions.cs |
@@ -16,15 +16,15 @@ |
{ |
private static readonly Func<string, string> directURIEscapeDataString = |
((Expression<Func<string, string>>) |
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766).AsParallel() |
.Select(o => Uri.EscapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - o*32766)))) |
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765) / 32766).AsParallel() |
.Select(o => Uri.EscapeDataString(data.Substring(o * 32766, Math.Min(32766, data.Length - o * 32766)))) |
.ToArray()))).Compile(); |
|
private static readonly Func<string, string> directURIUnescapeDataString = |
((Expression<Func<string, string>>) |
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766).AsParallel() |
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765) / 32766).AsParallel() |
.Select( |
o => Uri.UnescapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - o*32766)))) |
o => Uri.UnescapeDataString(data.Substring(o * 32766, Math.Min(32766, data.Length - o * 32766)))) |
.ToArray()))).Compile(); |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -91,4 +91,4 @@ |
return split.Length <= 1 || !long.TryParse(split[1], out port) ? 80 : port; |
} |
} |
} |
} |
/XML.cs |
@@ -23,7 +23,7 @@ |
Regex.Replace(data, |
@"(" + string.Join(@"|", @"&", @"<", @">", @""", @"'") + @")", |
@"", RegexOptions.IgnoreCase | RegexOptions.Multiline) |
.IndexOfAny(new[] {'&', '<', '>', '"', '\''}) |
.IndexOfAny(new[] { '&', '<', '>', '"', '\'' }) |
.Equals(-1))).Compile(); |
|
/////////////////////////////////////////////////////////////////////////// |
@@ -50,6 +50,7 @@ |
} |
t.Enqueue(c); |
break; |
|
case ';': |
if (!t.Count.Equals(0)) |
{ |
@@ -60,18 +61,23 @@ |
case "'": |
m.Append('\''); |
break; |
|
case """: |
m.Append('"'); |
break; |
|
case ">": |
m.Append('>'); |
break; |
|
case "<": |
m.Append('<'); |
break; |
|
case "&": |
m.Append('&'); |
break; |
|
default: // Unrecognized escape sequence |
m.Append(special); |
break; |
@@ -81,6 +87,7 @@ |
} |
m.Append(c); |
break; |
|
default: |
if (!t.Count.Equals(0)) |
{ |
@@ -119,18 +126,23 @@ |
case '&': |
result[o] = @"&"; |
break; |
|
case '<': |
result[o] = @"<"; |
break; |
|
case '>': |
result[o] = @">"; |
break; |
|
case '"': |
result[o] = @"""; |
break; |
|
case '\'': |
result[o] = @"'"; |
break; |
|
default: |
result[o] = s[o].ToString(); |
break; |
@@ -163,7 +175,7 @@ |
/// <param name="rename">the name to replace with</param> |
public static void RenameNodes(XElement root, string name, string rename) |
{ |
if (String.Equals(root.Name.LocalName, name, StringComparison.Ordinal)) |
if (string.Equals(root.Name.LocalName, name, StringComparison.Ordinal)) |
{ |
root.Name = rename; |
} |
@@ -174,4 +186,4 @@ |
} |
} |
} |
} |
} |