Exemplo n.º 1
0
        private static bool ProcessNonFixedLengthTest(StructureSegmentTest test, string value, ref int pos)
        {
            for (int occurrence = 0; occurrence < test.Occurrences; occurrence++)
            {
                if (pos >= value.Length)
                {
                    return(true);
                }

                char c = value[pos];
                if (!test.Test(c, pos))
                {
                    return(false);
                }

                pos++;
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool ValidateNonFixedLength(string iban)
        {
            int pos          = 0;
            int segmentIndex = 0;

            for (; segmentIndex < _segmentTests.Count; segmentIndex++)
            {
                StructureSegmentTest expectedStructureSegment = _segmentTests[segmentIndex];
                if (expectedStructureSegment.IsFixedLength)
                {
                    if (!ProcessFixedLengthTest(expectedStructureSegment, iban, ref pos))
                    {
                        return(false);
                    }
                }
                else
                {
                    ProcessNonFixedLengthTest(expectedStructureSegment, iban, ref pos);
                }
            }

            return(iban.Length == pos && segmentIndex == _segmentTests.Count);
        }
Exemplo n.º 3
0
        private bool ValidateFixedLength(string iban)
        {
            int pos          = 0;
            int segmentIndex = 0;

            // ReSharper disable once ForCanBeConvertedToForeach - justification : performance critical
            for (; segmentIndex < _segmentTests.Count; segmentIndex++)
            {
                StructureSegmentTest expectedStructureSegment = _segmentTests[segmentIndex];
                for (int occurrence = 0; occurrence < expectedStructureSegment.Occurrences; occurrence++)
                {
                    char c = iban[pos];
                    if (!expectedStructureSegment.Test(c, pos))
                    {
                        return(false);
                    }

                    pos++;
                }
            }

            return(iban.Length == pos && segmentIndex == _segmentTests.Count);
        }