Example #1
1
		public static int Parse(string s, NumberStyles style)
		{
			if (style == NumberStyles.HexNumber)
				return Native.API.intval(s, 16);

			return Native.API.intval(s);
		}
Example #2
0
 /// <summary>
 /// Parses aint value for the given string using the given number style and using
 /// the invariant culture parser.
 /// </summary>
 /// <param name="toParse">The value to parse.</param>
 /// <param name="ns">The number style used to parse the int value.</param>
 /// <returns>The int value of the string.</returns>
 public static int ccParseInt(string toParse, NumberStyles ns)
 {
     // http://www.cocos2d-x.org/boards/17/topics/11690
     // Issue #17
     // https://github.com/cocos2d/cocos2d-x-for-xna/issues/17
     return (int.Parse(toParse, ns, System.Globalization.CultureInfo.InvariantCulture));
 }
Example #3
0
		private static bool CheckStyle(NumberStyles style, bool tryParse, ref Exception exc)
		{
			if ((style & NumberStyles.AllowHexSpecifier) != 0)
			{
				NumberStyles ne = style ^ NumberStyles.AllowHexSpecifier;
				if ((ne & NumberStyles.AllowLeadingWhite) != 0)
				{
					ne ^= NumberStyles.AllowLeadingWhite;
				}
				if ((ne & NumberStyles.AllowTrailingWhite) != 0)
				{
					ne ^= NumberStyles.AllowTrailingWhite;
				}
				if (ne != 0)
				{
					if (!tryParse)
					{
						exc = new ArgumentException(
							"With AllowHexSpecifier only " +
							"AllowLeadingWhite and AllowTrailingWhite " +
							"are permitted.");
					}
					return false;
				}
			}

			return true;
		}
 public ParseTest(String str, Decimal d, NumberStyles style)
 {
     this.str = str;
     this.exceptionFlag = false;
     this.style = style;
     this.d = d;
 }
 public static bool IsNumeric(this string text, NumberStyles style = NumberStyles.Number, CultureInfo culture = null)
 {
     double number;
     if (culture == null)
         culture = CultureInfo.InvariantCulture;
     return double.TryParse(text, style, culture, out number) && !string.IsNullOrWhiteSpace(text);
 }
Example #6
0
        public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out sbyte result)
        {
            // Todo, consider how to implemente style and provider
            throw new NotImplementedException();

            //return TryParse(s, out result);
        }
Example #7
0
	// Parsing methods.
	public static byte Parse(String s, NumberStyles style,
							 IFormatProvider provider)
			{
				NumberParser.ValidateIntegerStyle(style);
				return Convert.ToByte(NumberParser.ParseUInt32
					(s, style, NumberFormatInfo.GetInstance(provider), 256));
			}
 public static Double ConvertToNumeric(object value, IFormatProvider provider, NumberStyles style)
 {
     var parsableString = value as String;
     if (parsableString == null)
     {
         var formatter = value as IFormattable;
         if (formatter != null)
         {
             string format = GeneralFormatter;
             if (formatter is Single || formatter is Double)
             {
                 format = RoundtripFormatter;
             }
             parsableString = formatter.ToString(format, provider);
         }
     }
     if (parsableString != null)
     {
         Double number;
         if (Double.TryParse(parsableString, style, provider, out number))
         {
             return number;
         }
     }
     throw new FormatException(Resources.Converter_Value_cant_be_parsed_to_numeric);
 }
Example #9
0
 private void InitializeMembers()
 {
     this.encoding = null;
     this.culture = null;
     this.numberStyle = NumberStyles.Float;
     this.dateTimeStyle = DateTimeStyles.None;
 }
Example #10
0
	public static ulong Parse(String s, NumberStyles style,
							  IFormatProvider provider)
			{
				NumberParser.ValidateIntegerStyle(style);
				return NumberParser.ParseUInt64
					(s, style, NumberFormatInfo.GetInstance(provider), 0);
			}
Example #11
0
	// Parsing methods.
	public static short Parse(String s, NumberStyles style,
							  IFormatProvider provider)
			{
				NumberParser.ValidateIntegerStyle(style);
				return Convert.ToInt16(NumberParser.ParseInt32
					(s, style, NumberFormatInfo.GetInstance(provider), 32768));
			}
Example #12
0
        /// <summary>
        /// Tries to convert a string representation into a numeric value.
        /// </summary>
        public static bool TryParseDecimal(string s, NumberStyles style, out decimal result)
        {
#if PocketPC
            try
            {
                result = decimal.Parse(s, style, CultureInfo.InvariantCulture);
                return true;
            }
            catch (ArgumentException)
            {
                result = Decimal.Zero;
                return false;
            }
            catch (FormatException)
            {
                result = Decimal.Zero;
                return false;
            }
            catch (OverflowException)
            {
                result = Decimal.Zero;
                return false;
            }

#else
            return decimal.TryParse(s, style, CultureInfo.InvariantCulture, out result);
#endif
        }
Example #13
0
 public CsvColumnAttribute(string name, int fieldIndex, bool canBeNull,
             string outputFormat, NumberStyles numberStyle, int charLength)
     : base(name, fieldIndex, canBeNull)
 {
     NumberStyle = numberStyle;
     OutputFormat = outputFormat;
     CharLength = charLength;
 }
Example #14
0
        /// <summary>Converts the string representation of a money value to its <see cref="Money"/> equivalent.</summary>
        /// <param name="value">The string representation of the number to convert.</param>
        /// <param name="style">A bitwise combination of enumeration values that indicates the permitted format of value. A typical value to specify is <see cref="NumberStyles.Currency"/>.</param>
        /// <param name="provider">An object that supplies culture-specific parsing information about <i>value</i>.</param>
        /// <param name="currency">The currency to use for parsing the string representation.</param>
        /// <returns>The equivalent to the money amount contained in <i>value</i>.</returns>
        /// <exception cref="System.ArgumentNullException"><i>value</i> is <b>null</b> or empty.</exception> 
        /// <exception cref="System.FormatException"><i>value</i> is not in the correct format or the currency sign matches with multiple known currencies!</exception>
        /// <exception cref="System.OverflowException"><i>value</i> represents a number less than <see cref="Decimal.MinValue"/> or greater than <see cref="Decimal.MaxValue"/>.</exception>
        public static Money Parse(string value, NumberStyles style, IFormatProvider provider, Currency currency)
        {
            if (string.IsNullOrWhiteSpace(value))
                throw new ArgumentNullException(nameof(value));

            decimal amount = decimal.Parse(value, style, GetNumberFormatInfo(currency, provider));
            return new Money(amount, currency);
        }
Example #15
0
        public static bool TryParse(string s, NumberStyles style, IFormatProvider provider, out byte result)
        {
            // Todo, consider how to implemente style and provider
            // Exponent, "1E0", "1e3"...
            // Decimal point "1.0", "3.5"
            throw new NotImplementedException();

            //return TryParse(s, out result);
        }
		public static sbyte? ToSByteOrNull(this string s, NumberStyles numberStyles, IFormatProvider formatProvider)
		{
			sbyte result;
			if(sbyte.TryParse(s, numberStyles, formatProvider,out result))
			{
				return result;
			}
			return null;
		}
		public static sbyte? ToSByteOrNull(this string s, NumberStyles numberStyles)
		{
			sbyte result;
			if(sbyte.TryParse(s, numberStyles, null, out result))
			{
				return result;
			}
			return null;
		}
		public static sbyte ToSByteOrDefault(this string s, NumberStyles numberStyles, IFormatProvider formatProvider, sbyte defaultValue = default(sbyte))
		{
			sbyte result;
			if(sbyte.TryParse(s,numberStyles, formatProvider, out result))
			{
				return result;
			}
			return defaultValue;
		}
 /// <summary>
 ///   Mono does not support the BigInteger.TryParse method. In practice,
 ///   we seldom actually need to parse huge integers, so it makes sense
 ///   to support most real-life cases by simply trying to parse using
 ///   Int64, and only falling back if needed.
 /// </summary>
 internal static BigInteger Parse(string str, NumberStyles style) {
     UInt64 parsed;
     if (UInt64.TryParse(str, style, NumberFormatInfo.CurrentInfo, out parsed)) {
         return new BigInteger(parsed);
     } else {
         // Throws on Mono 3.2.8
         return BigInteger.Parse(str, style);
     }
 }
Example #20
0
        public UnparsedNumber(string value, Type type, NumberStyles numberStyles)
        {
            Require.NotEmpty(value, "value");
            Require.NotNull(type, "type");

            Value = value;
            Type = type;
            NumberStyles = numberStyles;
        }
Example #21
0
        /// <summary>
        ///     Converts the string representation of a number in a specified numberStyle and culture-specific
        ///     format to its System.Byte equivalent. A return value indicates whether the
        ///     conversion succeeded or failed.
        /// </summary>
        /// <param name="value">
        ///     A string containing a number to convert. The string is interpreted using
        ///     the numberStyle specified by numberStyle.
        /// </param>
        /// <param name="numberStyle">
        ///     A bitwise combination of enumeration values that indicates the numberStyle elements
        ///     that can be present in s. A typical value to specify is System.Globalization.NumberStyles.Integer.
        /// </param>
        /// <param name="formatProvider">
        ///     An object that supplies culture-specific formatting information about s.
        ///     If formatProvider is null, the thread current culture is used.
        /// </param>
        /// <param name="outValue">
        ///     When this method returns, contains the 8-bit unsigned integer value equivalent
        ///     to the number contained in s if the conversion succeeded, or zero if the
        ///     conversion failed. The conversion fails if the s parameter is null or System.String.Empty,
        ///     is not of the correct format, or represents a number less than System.Byte.MinValue
        ///     or greater than System.Byte.MaxValue. This parameter is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsByte( this String value,
                                           NumberStyles numberStyle,
                                           IFormatProvider formatProvider,
                                           out Byte outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Byte.TryParse( value, numberStyle, formatProvider, out outValue );
        }
Example #22
0
        /// <summary>
        ///     Converts the string representation of a number in a specified numberStyles and culture-specific
        ///     format to its 32-bit signed integer equivalent. A return value indicates
        ///     whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="value">
        ///     A string containing a number to convert. The string is interpreted using
        /// </param>
        /// <param name="numberStyles">
        ///     A bitwise combination of enumeration values that indicates the numberStyles elements
        ///     that can be present in value. A typical value to specify is <see cref="NumberStyles.Integer" />.
        /// </param>
        /// <param name="formatProvider">An object that supplies culture-specific formatting information about value.</param>
        /// <param name="outValue">
        ///     When this method returns, contains the 32-bit signed integer value equivalent
        ///     to the number contained in s, if the conversion succeeded, or zero if the
        ///     conversion failed. The conversion fails if the s parameter is null or System.String.Empty,
        ///     is not in a format compliant with numberStyles, or represents a number less than
        ///     System.Int32.MinValue or greater than System.Int32.MaxValue. This parameter
        ///     is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsInt32( this String value,
                                            NumberStyles numberStyles,
                                            IFormatProvider formatProvider,
                                            out Int32 outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Int32.TryParse( value, numberStyles, formatProvider, out outValue );
        }
        /// <summary>
        ///     Converts the string representation of a number to its System.Decimal equivalent
        ///     using the specified numberStyle and culture-specific format. A return value indicates
        ///     whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="value">The string representation of the number to convert.</param>
        /// <param name="numberStyle">
        ///     A bitwise combination of enumeration values that indicates the permitted
        ///     format of value. A typical value to specify is System.Globalization.NumberStyles.Number.
        /// </param>
        /// <param name="formatProvider">An object that supplies culture-specific parsing information about value.</param>
        /// <param name="outValue">
        ///     When this method returns, contains the System.Decimal number that is equivalent
        ///     to the numeric value contained in s, if the conversion succeeded, or is zero
        ///     if the conversion failed. The conversion fails if the s parameter is null
        ///     or System.String.Empty, is not in a format compliant with numberStyle, or represents
        ///     a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue.
        ///     This parameter is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsDecimal( this String value,
                                              NumberStyles numberStyle,
                                              IFormatProvider formatProvider,
                                              out Decimal outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return Decimal.TryParse( value, NumberStyles.Any, CultureInfo.InvariantCulture, out outValue );
        }
Example #24
0
        public static bool IsDouble(string strValue, NumberStyles numberStyles)
        {
            bool isNum = true;
            double value;
            if (!String.IsNullOrEmpty(strValue))
                isNum = (double.TryParse(Convert.ToString(strValue), numberStyles, CultureInfo.CurrentCulture, out value) ||
                         double.TryParse(Convert.ToString(strValue), numberStyles, CultureInfo.InvariantCulture, out value));

            return isNum;
        }
        /// <summary>
        /// Converts a string to a <see cref="sbyte" />.
        /// </summary>
        /// <param name="str">The string to convert.</param>
        /// <param name="styles">The options.</param>
        /// <param name="provider">The custom provider to use.</param>
        /// <returns>
        /// The converted value or <see langword="null" /> if <paramref name="str" /> is
        /// <see langword="null" /> or contains whitespaces only.
        /// </returns>
        /// <exception cref="FormatException">
        /// <paramref name="str" /> has an invalid format.
        /// </exception>
        /// <exception cref="OverflowException">
        /// <paramref name="str" /> represents a value that is too big.
        /// </exception>
        public static sbyte? ToSByte(this string str,
                                     NumberStyles styles = NumberStyles.Integer, IFormatProvider provider = null)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return null;
            }

            return provider == null ? sbyte.Parse(str, styles)
                                    : sbyte.Parse(str, styles, provider);
        }
        /// <summary>
        /// Convert string value to long value
        /// </summary>
        /// <param name="strValue">string value to convert</param>
        /// <param name="defaultValue">default value when error on convert value</param>
        /// <param name="allowZero">allow zero on convert</param>
        /// <param name="numberStyle">string number style</param>
        /// <param name="culture">current culture</param>
        /// <returns>long value</returns>
        public static long TryParseLong(this string strValue, long defaultValue, bool allowZero, NumberStyles numberStyle, CultureInfo culture)
        {
            long longValue;
            var converted = long.TryParse(strValue, numberStyle, culture, out longValue);

            return converted
                ? longValue == 0 && !allowZero
                    ? defaultValue
                    : longValue
                : defaultValue;
        }
        /// <summary>
        /// Convert float string value in float value
        /// </summary>
        /// <param name="strValue">string to convert</param>
        /// <param name="defaultValue">default value to return on convert error</param>
        /// <param name="allowZero">allow 0 valuen on convert</param>
        /// <param name="numberStyle">number style to convert</param>
        /// <param name="culture">float culture origin</param>
        /// <returns>float value</returns>
        public static float TryParseFloat(this string strValue, float defaultValue, bool allowZero, NumberStyles numberStyle, CultureInfo culture)
        {
            float floatValue;
            var converted = float.TryParse(strValue, numberStyle, culture, out floatValue);

            return converted
                ? floatValue.Equals(0) && !allowZero
                    ? defaultValue
                    : floatValue
                : defaultValue;
        }
        /// <summary>
        /// <para>Convert string to short</para>
        /// <para>Set default value on error</para>
        /// </summary>
        /// <param name="strValue">string value</param>
        /// <param name="defaultValue">default value</param>
        /// <param name="allowZero">allow 0 on convert.</param>
        /// <param name="numberStyle">number style to convert</param>
        /// <param name="culture">culture origin</param>
        /// <returns>converted value or default value</returns>
        public static short TryParseShort(this string strValue, short defaultValue, bool allowZero, NumberStyles numberStyle, CultureInfo culture)
        {
            short shortValue;
            var converted = short.TryParse(strValue, numberStyle, culture, out shortValue);

            return converted
                ? shortValue == 0 && !allowZero
                    ? defaultValue
                    : shortValue
                : defaultValue;
        }
        /// <summary>
        /// Convert double string value in double value
        /// </summary>
        /// <param name="strValue">string to convert</param>
        /// <param name="defaultValue">default value to return on convert error</param>
        /// <param name="allowZero">allow 0 valuen on convert</param>
        /// <param name="numberStyle">number style to convert</param>
        /// <param name="culture">double culture origin</param>
        /// <returns>double value</returns>
        public static double TryParseDouble(this string strValue, double defaultValue, bool allowZero, NumberStyles numberStyle, CultureInfo culture)
        {
            double doubleValue;
            var converted = double.TryParse(strValue, numberStyle, culture, out doubleValue);

            return converted
                ? doubleValue.Equals(0) && !allowZero
                    ? defaultValue
                    : doubleValue
                : defaultValue;
        }
        /// <summary>
        /// Converts a string to an <see cref="uint" />.
        /// </summary>
        /// <param name="str">The string to convert.</param>
        /// <param name="styles">The options.</param>
        /// <param name="provider">The custom provider to use.</param>
        /// <returns>
        /// The converted value or <see langword="null" /> if <paramref name="str" /> is
        /// <see langword="null" /> or contains whitespaces only.
        /// </returns>
        /// <exception cref="FormatException">
        /// <paramref name="str" /> has an invalid format.
        /// </exception>
        /// <exception cref="OverflowException">
        /// <paramref name="str" /> represents a value that is too big.
        /// </exception>
        public static uint? ToUInt32(this string str,
                                     NumberStyles styles = NumberStyles.Integer, IFormatProvider provider = null)
        {
            if (string.IsNullOrWhiteSpace(str))
            {
                return null;
            }

            return provider == null ? uint.Parse(str, styles)
                                    : uint.Parse(str, styles, provider);
        }
Example #31
0
File: Int32.cs Project: z1c0/corert
 public static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, IFormatProvider provider, out int result)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result, out _));
 }
        /// <summary>
        /// Parse string array in decimal array
        /// </summary>
        /// <param name="strValue">string to parse</param>
        /// <param name="defaultValue">default value when default tryparse</param>
        /// <param name="allowDefaultConversion">Allow default tryparse values</param>
        /// <param name="numberStyle">number style to convert</param>
        /// <param name="culture">culture origin</param>
        /// <returns>decimal array</returns>
        public static decimal[] TryParseDecimalArray(this string strValue, decimal[] defaultValue, bool allowDefaultConversion, NumberStyles numberStyle, CultureInfo culture)
        {
            if (String.IsNullOrEmpty(strValue))
            {
                return defaultValue ?? new decimal[] { }
            }
            ;

            var decimalList = defaultValue != null
                ? defaultValue.ToList()
                : new List <decimal>();

            foreach (var l in strValue.Split(','))
            {
                var strDecimal = l ?? "";

                if (String.IsNullOrEmpty(strDecimal))
                {
                    if (allowDefaultConversion)
                    {
                        decimalList.Add(BasePrimitivesExtensions.GetDefaultDecimalConversionValue());
                    }

                    continue;
                }

                decimal decimalConvert;
                if (!decimal.TryParse(strDecimal, numberStyle, culture, out decimalConvert))
                {
                    if (allowDefaultConversion)
                    {
                        decimalList.Add(BasePrimitivesExtensions.GetDefaultDecimalConversionValue());
                    }
                }
                else
                {
                    decimalList.Add(decimalConvert);
                }
            }

            return(decimalList.ToArray());
        }
Example #33
0
        /// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse1"]/*' />
        public static int Parse(String s, NumberStyles style) {
			NumberFormatInfo.ValidateParseStyle(style);
		    return Parse(s, style, null);
        }
Example #34
0
 public static int Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.ParseInt32(s, style, NumberFormatInfo.CurrentInfo));
 }
Example #35
0
 public static int Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Example #36
0
 public static Either <TLeft, sbyte> ParseToSbyte <TLeft>(this string source, NumberStyles style, TLeft left)
 {
     return(SbyteParser.Parse <TLeft>(source, style, left));
 }
Example #37
0
 public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Single result)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     return(TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result));
 }
Example #38
0
 private static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info, out double result)
 {
     return(Number.TryParseDouble(s, style, info, out result));
 }
        /// <summary>
        /// Convert decimal string value in decimal value
        /// </summary>
        /// <param name="strValue">string to convert</param>
        /// <param name="defaultValue">default value to return on convert error</param>
        /// <param name="allowZero">allow 0 valuen on convert</param>
        /// <param name="numberStyle">number style to convert</param>
        /// <param name="culture">decimal culture origin</param>
        /// <returns>decimal value</returns>
        public static decimal TryParseDecimal(this string strValue, decimal defaultValue, bool allowZero, NumberStyles numberStyle, CultureInfo culture)
        {
            decimal decimalValue;
            var     converted = decimal.TryParse(strValue, numberStyle, culture, out decimalValue);

            return(converted
                ? decimalValue == 0 && !allowZero
                    ? defaultValue
                    : decimalValue
                : defaultValue);
        }
Example #40
0
 ValueTask <byte> IAsyncBinaryReader.ReadByteAsync(LengthFormat lengthFormat, DecodingContext context, NumberStyles style, IFormatProvider?provider, CancellationToken token)
 => StreamExtensions.ReadByteAsync(stream, lengthFormat, context, buffer, style, provider, token);
Example #41
0
        public static Raw_AniDB_Anime ProcessAnimeDetails(XmlDocument docAnime, int animeID)
        {
            // most of the genral anime data will be over written by the UDP command
            Raw_AniDB_Anime anime = new Raw_AniDB_Anime
            {
                AnimeID = animeID
            };

            // check if there is any data
            if (docAnime?["anime"]?.Attributes["id"]?.Value == null)
            {
                logger.Warn("AniDB ProcessAnimeDetails - Received no or invalid info in XML");
                return(null);
            }

            anime.Description  = TryGetProperty(docAnime, "anime", "description")?.Replace('`', '\'');
            anime.AnimeTypeRAW = TryGetProperty(docAnime, "anime", "type");


            string episodecount = TryGetProperty(docAnime, "anime", "episodecount");

            int.TryParse(episodecount, out int epCount);
            anime.EpisodeCount       = epCount;
            anime.EpisodeCountNormal = epCount;

            int convertedAirDate = AniDB.GetAniDBDateAsSeconds(TryGetProperty(docAnime, "anime", "startdate"), true);
            int convertedEndDate = AniDB.GetAniDBDateAsSeconds(TryGetProperty(docAnime, "anime", "enddate"), false);

            //anime.AirDate = TryGetProperty(docAnime, "anime", "startdate");
            //anime.EndDate = TryGetProperty(docAnime, "anime", "enddate");

            anime.AirDate = AniDB.GetAniDBDateAsDate(convertedAirDate);
            anime.EndDate = AniDB.GetAniDBDateAsDate(convertedEndDate);

            anime.BeginYear = anime.AirDate?.Year ?? 0;
            anime.EndYear   = anime.EndDate?.Year ?? 0;

            //string enddate = TryGetProperty(docAnime, "anime", "enddate");

            string restricted = docAnime["anime"].Attributes["restricted"]?.Value;

            if (bool.TryParse(restricted, out bool res))
            {
                anime.Restricted = res ? 1 : 0;
            }
            else
            {
                anime.Restricted = 0;
            }

            anime.URL     = TryGetProperty(docAnime, "anime", "url");
            anime.Picname = TryGetProperty(docAnime, "anime", "picture");

            anime.DateTimeUpdated     = DateTime.Now;
            anime.DateTimeDescUpdated = anime.DateTimeUpdated;
            anime.ImageEnabled        = 1;

            #region Related Anime

            XmlNodeList raItems = docAnime["anime"]["relatedanime"]?.GetElementsByTagName("anime");
            if (raItems != null)
            {
                anime.RelatedAnimeIdsRAW   = string.Empty;
                anime.RelatedAnimeTypesRAW = string.Empty;

                foreach (XmlNode node in raItems)
                {
                    if (node?.Attributes?["id"]?.Value == null)
                    {
                        continue;
                    }
                    if (!int.TryParse(node.Attributes["id"].Value, out int id))
                    {
                        continue;
                    }
                    int relType = ConvertReltTypeTextToEnum(TryGetAttribute(node, "type"));

                    if (anime.RelatedAnimeIdsRAW.Length > 0)
                    {
                        anime.RelatedAnimeIdsRAW += "'";
                    }
                    if (anime.RelatedAnimeTypesRAW.Length > 0)
                    {
                        anime.RelatedAnimeTypesRAW += "'";
                    }

                    anime.RelatedAnimeIdsRAW   += id.ToString();
                    anime.RelatedAnimeTypesRAW += relType.ToString();
                }
            }

            #endregion

            #region Titles

            XmlNodeList titleItems = docAnime["anime"]["titles"]?.GetElementsByTagName("title");
            if (titleItems != null)
            {
                foreach (XmlNode node in titleItems)
                {
                    string titleType = node?.Attributes?["type"]?.Value?.Trim().ToLower();
                    if (string.IsNullOrEmpty(titleType))
                    {
                        continue;
                    }
                    string languageType = node.Attributes["xml:lang"]?.Value?.Trim().ToLower();
                    if (string.IsNullOrEmpty(languageType))
                    {
                        continue;
                    }
                    string titleValue = node.InnerText.Trim();
                    if (string.IsNullOrEmpty(titleValue))
                    {
                        continue;
                    }

                    if (titleType.Trim().ToUpper().Equals("MAIN"))
                    {
                        anime.MainTitle = titleValue.Replace('`', '\'');
                    }
                }
            }

            #endregion

            #region Ratings

            // init ratings
            anime.VoteCount       = 0;
            anime.TempVoteCount   = 0;
            anime.Rating          = 0;
            anime.TempRating      = 0;
            anime.ReviewCount     = 0;
            anime.AvgReviewRating = 0;

            NumberStyles style   = NumberStyles.Number;
            CultureInfo  culture = CultureInfo.CreateSpecificCulture("en-GB");

            XmlNodeList ratingItems = docAnime["anime"]["ratings"]?.ChildNodes;
            if (ratingItems == null)
            {
                return(anime);
            }
            foreach (XmlNode node in ratingItems)
            {
                string name = node?.Name?.Trim().ToLower();
                if (string.IsNullOrEmpty(name))
                {
                    continue;
                }
                if (!int.TryParse(TryGetAttribute(node, "count"), out int iCount))
                {
                    continue;
                }
                if (!decimal.TryParse(node.InnerText.Trim(), style, culture, out decimal iRating))
                {
                    continue;
                }
                iRating = (int)Math.Round(iRating * 100);

                if (name.Equals("permanent"))
                {
                    anime.VoteCount = iCount;
                    anime.Rating    = (int)iRating;
                }
                else if (name.Equals("temporary"))
                {
                    anime.TempVoteCount = iCount;
                    anime.TempRating    = (int)iRating;
                }
                else if (name.Equals("review"))
                {
                    anime.ReviewCount     = iCount;
                    anime.AvgReviewRating = (int)iRating;
                }
            }

            #endregion

            return(anime);
        }
Example #42
0
 public static bool TryParse(ReadOnlySpan <char> s, out Int16 result, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result));
 }
Example #43
0
 public override bool TryParse(string text, NumberStyles numberStyles, IFormatProvider culture, out int result)
 {
     return(int.TryParse(text, numberStyles, culture, out result));
 }
Example #44
0
 public NullableSingleConverter(IFormatProvider formatProvider, NumberStyles numberStyles)
     : base(new SingleConverter(formatProvider, numberStyles))
 {
 }
Example #45
0
 public NumericTextBox()
 {
     numberStyle = NumberStyles.Decimal;
     maxValue    = uint.MaxValue - 1;
     //Value = 0;
 }
Example #46
0
File: Int32.cs Project: z1c0/corert
 public static int Parse(ReadOnlySpan <char> s, NumberStyles style = NumberStyles.Integer, IFormatProvider provider = null)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.ParseInt32(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Example #47
0
 private static float Parse(String s, NumberStyles style, NumberFormatInfo info)
 {
     return(Number.ParseSingle(s, style, info));
 }
Example #48
0
 public static float Parse(String s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     return(Parse(s, style, NumberFormatInfo.CurrentInfo));
 }
Example #49
0
 public static Boolean TryParse(String s, NumberStyles style, IFormatProvider provider, out Int64 result)
 {
     UInt32.ValidateParseStyleInteger(style);
     return(FormatProvider.TryParseInt64(s, style, provider, out result));
 }
Example #50
0
    	// Parses an integer from a String in the given style.  If
    	// a NumberFormatInfo isn't specified, the current culture's 
    	// NumberFormatInfo is assumed.
    	// 
    	/// <include file='doc\Int32.uex' path='docs/doc[@for="Int32.Parse3"]/*' />
    	public static int Parse(String s, NumberStyles style, IFormatProvider provider) {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);
			NumberFormatInfo.ValidateParseStyle(style);
            return Number.ParseInt32(s, style, info);
        }
Example #51
0
 public static float Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     return(Parse(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Example #52
0
 // Parses a long from a String in the given style.  If
 // a NumberFormatInfo isn't specified, the current culture's
 // NumberFormatInfo is assumed.
 //
 public static long Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     UInt32.ValidateParseStyleInteger(style);
     return(FormatProvider.ParseInt64(s, style, provider));
 }
Example #53
0
 public static bool TryParse(String s, NumberStyles style, IFormatProvider provider, out Int32 result)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     return(Number.TryParseInt32(s, style, NumberFormatInfo.GetInstance(provider), out result));
 }
    static bool IsValidPrecision(string s, NumberStyles style, IFormatProvider provider)
    {
        var precision = GetPrecision(s, style, NumberFormatInfo.GetInstance(provider));

        return(precision <= 29);
    }
 public static bool TryParseExact(string s, out decimal result, NumberStyles style = NumberStyles.Number, IFormatProvider provider = null)
 {
     // NOTE: Always call base method first
     return(decimal.TryParse(s, style, provider, out result) && !IsValidPrecision(s, style, provider));
 }
 /// <summary>
 /// Parse string array in decimal array
 /// </summary>
 /// <param name="strValue">string to parse</param>
 /// <param name="numberStyle">number style to convert</param>
 /// <param name="culture">culture origin</param>
 /// <returns>decimal array</returns>
 public static decimal[] TryParseDecimalArray(this string strValue, NumberStyles numberStyle, CultureInfo culture)
 {
     return(strValue.TryParseDecimalArray(null,
                                          BasePrimitivesExtensions.GetDefaultDecimalArrayAllowDefaultConversion(),
                                          numberStyle, culture));
 }
Example #57
0
 public static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, IFormatProvider?provider, out double result)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     return(TryParse(s, style, NumberFormatInfo.GetInstance(provider), out result));
 }
 /// <summary>
 /// Tries to parse the specified string and convert it to double
 /// </summary>
 /// <param name="input">The string input to be parsed</param>
 /// <param name="style">The supported <see cref="NumberStyles"/></param>
 /// <param name="format">The format used for parsing</param>
 /// <param name="result">The parsing result</param>
 /// <returns>True if parsing succeeds, false otherwise</returns>
 protected override bool TryParseNumber(string input, NumberStyles style, IFormatProvider format, out double result)
 {
     return(double.TryParse(input, style, format, out result));
 }
 public IUInt64PropertyMapping NumberStyles(NumberStyles styles)
 {
     column.NumberStyles = styles;
     return(this);
 }
 protected abstract IModelBinder GetBinder(NumberStyles numberStyles);