You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
@@ -26,8 +26,8 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows.Converters;
|
||||
using System.Windows.Markup;
|
||||
|
||||
@@ -109,29 +109,84 @@ namespace System.Windows {
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
unchecked
|
||||
{
|
||||
var hashCode = _x;
|
||||
hashCode = (hashCode * 397) ^ _y;
|
||||
hashCode = (hashCode * 397) ^ _width;
|
||||
hashCode = (hashCode * 397) ^ _height;
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public static Int32Rect Parse (string source)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
Int32Rect value;
|
||||
if (source.Trim () == "Empty")
|
||||
{
|
||||
value = Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
|
||||
int x;
|
||||
int y;
|
||||
int width;
|
||||
int height;
|
||||
if (int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out x)
|
||||
&& int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out y)
|
||||
&& int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out width)
|
||||
&& int.TryParse (tokenizer.GetNextToken (), NumberStyles.Integer, CultureInfo.InvariantCulture, out height))
|
||||
{
|
||||
if (!tokenizer.HasNoMoreTokens ())
|
||||
{
|
||||
throw new InvalidOperationException ("Invalid Int32Rect format: " + source);
|
||||
}
|
||||
value = new Int32Rect (x, y, width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException (string.Format ("Invalid Int32Rect format: {0}", source));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
if (IsEmpty)
|
||||
return "Empty";
|
||||
return String.Format ("{0},{1},{2},{3}", _x, _y, _width, _height);
|
||||
return ToString (null);
|
||||
}
|
||||
|
||||
public string ToString (IFormatProvider provider)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
return ToString (null, provider);
|
||||
}
|
||||
|
||||
string IFormattable.ToString (string format, IFormatProvider provider)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
return ToString (provider);
|
||||
}
|
||||
|
||||
private string ToString (string format, IFormatProvider provider)
|
||||
{
|
||||
if (IsEmpty)
|
||||
return "Empty";
|
||||
|
||||
if (provider == null)
|
||||
provider = CultureInfo.CurrentCulture;
|
||||
|
||||
if (format == null)
|
||||
format = string.Empty;
|
||||
|
||||
var separator = NumericListTokenizer.GetSeparator (provider);
|
||||
|
||||
var rectFormat = string.Format (
|
||||
"{{0:{0}}}{1}{{1:{0}}}{1}{{2:{0}}}{1}{{3:{0}}}",
|
||||
format, separator);
|
||||
return string.Format (provider, rectFormat,
|
||||
_x, _y, _width, _height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
102
mcs/class/WindowsBase/System.Windows/NumericListTokenizer.cs
Normal file
102
mcs/class/WindowsBase/System.Windows/NumericListTokenizer.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace System.Windows
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class for parsing serialized data structures from the System.Windows namespace.
|
||||
/// </summary>
|
||||
internal class NumericListTokenizer
|
||||
{
|
||||
private readonly string _str;
|
||||
private readonly char _separator;
|
||||
private int _position;
|
||||
|
||||
private enum Symbol
|
||||
{
|
||||
Token,
|
||||
Separator,
|
||||
Whitspace,
|
||||
EndOfLine
|
||||
}
|
||||
|
||||
public NumericListTokenizer (string str, IFormatProvider formatProvider)
|
||||
{
|
||||
_str = str ?? throw new ArgumentNullException (nameof(str));
|
||||
_separator = GetSeparator (formatProvider ?? throw new ArgumentNullException (nameof(formatProvider)));
|
||||
}
|
||||
|
||||
public static char GetSeparator (IFormatProvider formatProvider)
|
||||
{
|
||||
// By convention, string representations of target classes always use ';' as a separator
|
||||
// if the decimal number separator is ','. Otherwise, the separator is ','.
|
||||
return NumberFormatInfo.GetInstance (formatProvider).NumberDecimalSeparator != "," ? ',' : ';';
|
||||
}
|
||||
|
||||
private Symbol GetCurrentSymbol ()
|
||||
{
|
||||
if (_position >= _str.Length)
|
||||
return Symbol.EndOfLine;
|
||||
if (_str[_position] == _separator)
|
||||
return Symbol.Separator;
|
||||
if (char.IsWhiteSpace (_str, _position))
|
||||
return Symbol.Whitspace;
|
||||
return Symbol.Token;
|
||||
}
|
||||
|
||||
private void SkipAllWhitespaces ()
|
||||
{
|
||||
while (GetCurrentSymbol () == Symbol.Whitspace)
|
||||
{
|
||||
_position++;
|
||||
}
|
||||
}
|
||||
|
||||
private void SkipNextDelimeter ()
|
||||
{
|
||||
SkipAllWhitespaces ();
|
||||
switch (GetCurrentSymbol ())
|
||||
{
|
||||
case Symbol.Token:
|
||||
return;
|
||||
case Symbol.Separator:
|
||||
_position++;
|
||||
SkipAllWhitespaces ();
|
||||
return;
|
||||
default:
|
||||
throw new InvalidOperationException ("Separator not found");
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasNoMoreTokens ()
|
||||
{
|
||||
SkipAllWhitespaces ();
|
||||
return GetCurrentSymbol () == Symbol.EndOfLine;
|
||||
}
|
||||
|
||||
public string GetNextToken ()
|
||||
{
|
||||
var length = 0;
|
||||
if (_position == 0)
|
||||
{
|
||||
SkipAllWhitespaces ();
|
||||
}
|
||||
else
|
||||
{
|
||||
SkipNextDelimeter ();
|
||||
}
|
||||
|
||||
while (GetCurrentSymbol () == Symbol.Token)
|
||||
{
|
||||
_position++;
|
||||
length++;
|
||||
}
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
throw new InvalidOperationException ("Next token not found");
|
||||
}
|
||||
|
||||
return _str.Substring (_position - length, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,15 +147,21 @@ namespace System.Windows {
|
||||
|
||||
public static Point Parse (string source)
|
||||
{
|
||||
string[] points = source.Split(',');
|
||||
|
||||
if (points.Length<2)
|
||||
throw new InvalidOperationException ("source does not contain two numbers");
|
||||
if (points.Length > 2)
|
||||
throw new InvalidOperationException ("source contains too many delimiters");
|
||||
|
||||
CultureInfo ci = CultureInfo.InvariantCulture;
|
||||
return new Point (Convert.ToDouble(points[0],ci), Convert.ToDouble(points[1],ci));
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
|
||||
double x;
|
||||
double y;
|
||||
if (!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out x) ||
|
||||
!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out y))
|
||||
{
|
||||
throw new FormatException (string.Format ("Invalid Point format: {0}", source));
|
||||
}
|
||||
if (!tokenizer.HasNoMoreTokens ())
|
||||
{
|
||||
throw new InvalidOperationException ("Invalid Point format: " + source);
|
||||
}
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
@@ -170,18 +176,13 @@ namespace System.Windows {
|
||||
|
||||
private string ToString(string format,IFormatProvider formatProvider)
|
||||
{
|
||||
CultureInfo ci = (CultureInfo)formatProvider;
|
||||
|
||||
if (ci == null)
|
||||
ci = CultureInfo.CurrentCulture;
|
||||
string seperator = ci.NumberFormat.NumberDecimalSeparator;
|
||||
if (seperator.Equals(","))
|
||||
seperator = ";";
|
||||
else
|
||||
seperator = ",";
|
||||
object[] ob = { this._x, seperator, this._y };
|
||||
|
||||
return string.Format(formatProvider, "{0:" + format + "}{1}{2:" + format + "}", ob);
|
||||
if (formatProvider == null)
|
||||
formatProvider = CultureInfo.CurrentCulture;
|
||||
if (format == null)
|
||||
format = string.Empty;
|
||||
var separator = NumericListTokenizer.GetSeparator (formatProvider);
|
||||
var pointFormat = string.Format ("{{0:{0}}}{1}{{1:{0}}}", format, separator);
|
||||
return string.Format (formatProvider, pointFormat, _x, _y);
|
||||
}
|
||||
|
||||
string IFormattable.ToString (string format, IFormatProvider formatProvider)
|
||||
|
||||
@@ -24,10 +24,8 @@
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Converters;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
@@ -121,7 +119,14 @@ namespace System.Windows {
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
unchecked
|
||||
{
|
||||
var hashCode = _x.GetHashCode ();
|
||||
hashCode = (hashCode * 397) ^ _y.GetHashCode ();
|
||||
hashCode = (hashCode * 397) ^ _width.GetHashCode ();
|
||||
hashCode = (hashCode * 397) ^ _height.GetHashCode ();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains (Rect rect)
|
||||
@@ -296,7 +301,37 @@ namespace System.Windows {
|
||||
|
||||
public static Rect Parse (string source)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
Rect value;
|
||||
if (source.Trim () == "Empty")
|
||||
{
|
||||
value = Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
|
||||
double x;
|
||||
double y;
|
||||
double width;
|
||||
double height;
|
||||
if (double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out x)
|
||||
&& double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out y)
|
||||
&& double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out width)
|
||||
&& double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out height))
|
||||
{
|
||||
if (!tokenizer.HasNoMoreTokens ())
|
||||
{
|
||||
throw new InvalidOperationException ("Invalid Rect format: " + source);
|
||||
}
|
||||
value = new Rect (x, y, width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new FormatException (string.Format ("Invalid Rect format: {0}", source));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
@@ -325,17 +360,12 @@ namespace System.Windows {
|
||||
if (format == null)
|
||||
format = string.Empty;
|
||||
|
||||
string separator = ",";
|
||||
NumberFormatInfo numberFormat =
|
||||
provider.GetFormat (typeof (NumberFormatInfo)) as NumberFormatInfo;
|
||||
if (numberFormat != null &&
|
||||
numberFormat.NumberDecimalSeparator == separator)
|
||||
separator = ";";
|
||||
var separator = NumericListTokenizer.GetSeparator (provider);
|
||||
|
||||
string rectFormat = String.Format (
|
||||
var rectFormat = string.Format (
|
||||
"{{0:{0}}}{1}{{1:{0}}}{1}{{2:{0}}}{1}{{3:{0}}}",
|
||||
format, separator);
|
||||
return String.Format (provider, rectFormat,
|
||||
return string.Format (provider, rectFormat,
|
||||
_x, _y, _width, _height);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows.Converters;
|
||||
using System.Windows.Markup;
|
||||
|
||||
@@ -64,29 +65,63 @@ namespace System.Windows {
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
unchecked
|
||||
{
|
||||
return (_width.GetHashCode () * 397) ^ _height.GetHashCode ();
|
||||
}
|
||||
}
|
||||
|
||||
public static Size Parse (string source)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
Size value;
|
||||
if (source.Trim () == "Empty")
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
|
||||
double width;
|
||||
double height;
|
||||
if (!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out width) ||
|
||||
!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out height))
|
||||
{
|
||||
throw new FormatException (string.Format ("Invalid Size format: {0}", source));
|
||||
}
|
||||
if (!tokenizer.HasNoMoreTokens ())
|
||||
{
|
||||
throw new InvalidOperationException ("Invalid Size format: " + source);
|
||||
}
|
||||
return new Size(width, height);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
if (IsEmpty)
|
||||
return "Empty";
|
||||
return String.Format ("{0},{1}", _width, _height);
|
||||
return ConvertToString (null, null);
|
||||
}
|
||||
|
||||
public string ToString (IFormatProvider provider)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
return ConvertToString (null, provider);
|
||||
}
|
||||
|
||||
string IFormattable.ToString (string format, IFormatProvider provider)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
return ConvertToString (format, provider);
|
||||
}
|
||||
|
||||
private string ConvertToString (string format, IFormatProvider provider)
|
||||
{
|
||||
if (IsEmpty)
|
||||
return "Empty";
|
||||
|
||||
if (provider == null)
|
||||
provider = CultureInfo.CurrentCulture;
|
||||
if (format == null)
|
||||
format = string.Empty;
|
||||
var separator = NumericListTokenizer.GetSeparator (provider);
|
||||
var vectorFormat = string.Format ("{{0:{0}}}{1}{{1:{0}}}", format, separator);
|
||||
return string.Format (provider, vectorFormat, _width, _height);
|
||||
}
|
||||
|
||||
public bool IsEmpty {
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
// Chris Toshok (toshok@novell.com)
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Windows.Converters;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
@@ -57,12 +57,10 @@ namespace System.Windows {
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
string IFormattable.ToString (string format, IFormatProvider provider)
|
||||
{
|
||||
return string.Format (provider, "{0:" + format + "},{1:" + format + "}", _x, _y);
|
||||
unchecked
|
||||
{
|
||||
return (_x.GetHashCode () * 397) ^ _y.GetHashCode ();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Equals (Vector vector1, Vector vector2)
|
||||
@@ -150,17 +148,47 @@ namespace System.Windows {
|
||||
|
||||
public static Vector Parse (string source)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
if (source == null)
|
||||
throw new ArgumentNullException ("source");
|
||||
var tokenizer = new NumericListTokenizer (source, CultureInfo.InvariantCulture);
|
||||
double x;
|
||||
double y;
|
||||
if (!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out x) ||
|
||||
!double.TryParse (tokenizer.GetNextToken (), NumberStyles.Float, CultureInfo.InvariantCulture, out y))
|
||||
{
|
||||
throw new FormatException (string.Format ("Invalid Vector format: {0}", source));
|
||||
}
|
||||
if (!tokenizer.HasNoMoreTokens ())
|
||||
{
|
||||
throw new InvalidOperationException("Invalid Vector format: " + source);
|
||||
}
|
||||
return new Vector(x, y);
|
||||
}
|
||||
|
||||
public override string ToString ()
|
||||
{
|
||||
return String.Format ("{0},{1}", _x, _y);
|
||||
return ToString(null);
|
||||
}
|
||||
|
||||
public string ToString (IFormatProvider provider)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
return ToString (null, provider);
|
||||
}
|
||||
|
||||
string IFormattable.ToString (string format, IFormatProvider provider)
|
||||
{
|
||||
return ToString (format, provider);
|
||||
}
|
||||
|
||||
private string ToString(string format,IFormatProvider formatProvider)
|
||||
{
|
||||
if (formatProvider == null)
|
||||
formatProvider = CultureInfo.CurrentCulture;
|
||||
if (format == null)
|
||||
format = string.Empty;
|
||||
var separator = NumericListTokenizer.GetSeparator (formatProvider);
|
||||
var vectorFormat = string.Format ("{{0:{0}}}{1}{{1:{0}}}", format, separator);
|
||||
return string.Format (formatProvider, vectorFormat, _x, _y);
|
||||
}
|
||||
|
||||
public double Length {
|
||||
|
||||
Reference in New Issue
Block a user