示例#1
0
        public List <ErrorReporting> Verify(ISegmentPair segmentPair, List <ExcludedRange> sourceExcludedRanges = null, List <ExcludedRange> targetExcludedRanges = null)
        {
            var errors = new List <ErrorReporting>();

            if (!VerificationSettings.ReportNumberFormatErrors)
            {
                return(errors);
            }

            var sourceText         = TextGenerator.GetPlainText(segmentPair.Source, false);
            var sourceNumberTokens = GetNumbersTokens(sourceText,
                                                      VerificationSettings.GetSourceDecimalSeparators(),
                                                      VerificationSettings.GetSourceThousandSeparators(), sourceExcludedRanges);

            var targetText         = TextGenerator.GetPlainText(segmentPair.Target, false);
            var targetNumberTokens = GetNumbersTokens(targetText,
                                                      VerificationSettings.GetTargetDecimalSeparators(),
                                                      VerificationSettings.GetTargetThousandSeparators(), targetExcludedRanges);

            foreach (var numberToken in targetNumberTokens.Where(a => !a.Valid))
            {
                errors.AddRange(GetErrorMessages(numberToken, false));
            }

            return(errors);
        }
示例#2
0
        private void RemoveNonAlphanumericals(bool isSource, List <string> normalizedAlphaList)
        {
            var thoAndDecSeparators = new List <string>();

            if (isSource)
            {
                thoAndDecSeparators.AddRange(VerificationSettings.GetSourceThousandSeparators());
                thoAndDecSeparators.AddRange(VerificationSettings.GetSourceDecimalSeparators());
            }
            else
            {
                thoAndDecSeparators.AddRange(VerificationSettings.GetTargetThousandSeparators());
                thoAndDecSeparators.AddRange(VerificationSettings.GetTargetDecimalSeparators());
            }
            thoAndDecSeparators.RemoveAll(string.IsNullOrEmpty);

            var forRemoval = new List <string>();

            foreach (var item in normalizedAlphaList)
            {
                var itemWoSeparators = item;

                thoAndDecSeparators.ForEach(sep => itemWoSeparators = itemWoSeparators.Replace(sep, ""));

                var unitsOfMeasurement = "(^(?![A-Za-z]))\\d+[a-z]+$";
                if (Regex.Match(itemWoSeparators, unitsOfMeasurement).Success || int.TryParse(itemWoSeparators, out _))
                {
                    forRemoval.Add(item);
                }
            }
            forRemoval.ForEach(item => normalizedAlphaList.Remove(item));
        }
示例#3
0
        public void Initialize(IDocumentProperties documentInfo)
        {
            _sourceMatchingThousandSeparators = string.Concat(VerificationSettings.GetSourceThousandSeparators());
            _targetMatchingThousandSeparators = string.Concat(VerificationSettings.GetTargetThousandSeparators());
            _sourceMatchingDecimalSeparators  = string.Concat(VerificationSettings.GetSourceDecimalSeparators());
            _targetMatchingDecimalSeparators  = string.Concat(VerificationSettings.GetTargetDecimalSeparators());

            _targetMatchingDecimalSeparators += VerificationSettings.TargetDecimalComma ? @"\u002C" : string.Empty;
            _targetMatchingDecimalSeparators += VerificationSettings.TargetDecimalPeriod ? @"\u002E" : string.Empty;
            _targetMatchingDecimalSeparators += VerificationSettings.TargetDecimalCustomSeparator
                ? VerificationSettings.GetTargetDecimalCustomSeparator
                : string.Empty;


            //used in NoSeparator method, we need the character chosed not the code.
            _sourceThousandSeparators += VerificationSettings.SourceThousandsSpace ? " " : string.Empty;
            _sourceThousandSeparators += VerificationSettings.SourceThousandsNobreakSpace ? " " : string.Empty;
            _sourceThousandSeparators += VerificationSettings.SourceThousandsThinSpace ? " " : string.Empty;
            _sourceThousandSeparators += VerificationSettings.SourceThousandsNobreakThinSpace ? " " : string.Empty;
            _sourceThousandSeparators += VerificationSettings.SourceThousandsComma ? "," : string.Empty;
            _sourceThousandSeparators += VerificationSettings.SourceThousandsPeriod ? "." : string.Empty;
            _sourceThousandSeparators += VerificationSettings.SourceThousandsCustomSeparator
                ? VerificationSettings.GetSourceThousandsCustomSeparator
                : string.Empty;

            _sourceDecimalSeparators += VerificationSettings.SourceDecimalComma ? "," : string.Empty;
            _sourceDecimalSeparators += VerificationSettings.SourceDecimalPeriod ? "." : string.Empty;
            _sourceDecimalSeparators += VerificationSettings.SourceDecimalCustomSeparator
                ? VerificationSettings.GetSourceDecimalCustomSeparator
                : string.Empty;

            _targetThousandSeparators += VerificationSettings.TargetThousandsSpace ? " " : string.Empty;
            _targetThousandSeparators += VerificationSettings.TargetThousandsNobreakSpace ? " " : string.Empty;
            _targetThousandSeparators += VerificationSettings.TargetThousandsThinSpace ? " " : string.Empty;
            _targetThousandSeparators += VerificationSettings.TargetThousandsNobreakThinSpace ? " " : string.Empty;
            _targetThousandSeparators += VerificationSettings.TargetThousandsComma ? "," : string.Empty;
            _targetThousandSeparators += VerificationSettings.TargetThousandsPeriod ? "." : string.Empty;
            _targetThousandSeparators += VerificationSettings.TargetThousandsCustomSeparator
                ? VerificationSettings.GetTargetThousandsCustomSeparator
                : string.Empty;
            _targetDecimalSeparators += VerificationSettings.TargetDecimalComma ? "," : string.Empty;
            _targetDecimalSeparators += VerificationSettings.TargetDecimalPeriod ? "." : string.Empty;
            _targetDecimalSeparators += VerificationSettings.TargetDecimalCustomSeparator
                ? VerificationSettings.GetSourceDecimalCustomSeparator
                : string.Empty;
        }