private int GetPoemCount() { if (Ranges?.Count == 0) { return(0); } int n = 0; foreach (AlnumRange range in Ranges) { if (range.A == null) { continue; // defensive } if (range.B != null) { Alphanumeric start = Alphanumeric.Parse(range.A); Alphanumeric end = Alphanumeric.Parse(range.B); if (!start.IsNull() && !end.IsNull() && start.Alpha == null && end.Alpha == null) { n += (int)end.Number - (int)start.Number; } } else { n++; } } return(n); }
/// <summary>Converts the string to an IBAN. /// A return value indicates whether the conversion succeeded. /// </summary> /// <param name="s"> /// A string containing an IBAN to convert. /// </param> /// <param name="formatProvider"> /// The specified format provider. /// </param> /// <param name="result"> /// The result of the parsing. /// </param> /// <returns> /// True if the string was converted successfully, otherwise false. /// </returns> public static bool TryParse(string s, IFormatProvider formatProvider, out InternationalBankAccountNumber result) { result = InternationalBankAccountNumber.Empty; if (string.IsNullOrEmpty(s)) { return(true); } var culture = formatProvider as CultureInfo ?? CultureInfo.InvariantCulture; if (Qowaiv.Unknown.IsUnknown(s, culture)) { result = Unknown; return(true); } if (Pattern.IsMatch(s)) { var str = Parsing.ClearSpacingToUpper(s); var country = Country.TryParse(str.Substring(0, 2)); Regex localizedPattern; if (str.Length > 11 && !country.IsEmptyOrUnknown() && (!LocalizedPatterns.TryGetValue(country, out localizedPattern) || localizedPattern.IsMatch(str))) { var validation = Alphanumeric.Replace(str.Substring(4) + str.Substring(0, 4), AlphanumericToNumeric); int sum = 0; int exp = 1; for (int pos = validation.Length - 1; pos >= 0; pos--) { sum += exp * AlphanumericAndNumericLookup.IndexOf(validation[pos]); exp = (exp * 10) % 97; } if ((sum % 97) == 1) { result = new InternationalBankAccountNumber() { m_Value = str }; return(true); } } } return(false); }
public static void AlphanumericParserIncorrect() => AssertThat(() => Alphanumeric.Parse("-yz")).ThrowsExactlyException <ParseException>();
public static void AlphanumericParserCorrectNumerical() => AssertThat(Alphanumeric.Parse("987")).IsEqualTo('9');
public static void TrimParserCorrect() => AssertThat(Alphanumeric.Trim().Parse("\tx yz")).IsEqualTo('x');
public static void AlphanumericParserCorrectAlphabetical() => AssertThat(Alphanumeric.Parse("xyz")).IsEqualTo('x');
static void TestDelegate2() => Alphanumeric.GetStr(null);
static void TestDelegate() => Alphanumeric.GetStr(string.Empty);