コード例 #1
0
        private IList <BarcodeSegment> Decode(string text)
        {
            if (decoder == null)
            {
                BarcodeSegment segment = new BarcodeSegment();
                segment.Text = text;

                IList <BarcodeSegment> segments = new List <BarcodeSegment>();
                segments.Add(segment);

                return(segments);
            }
            else
            {
                return(decoder.Decode(text));
            }
        }
コード例 #2
0
        public IList <BarcodeSegment> Decode(string text)
        {
            IList <BarcodeSegment> segments = new List <BarcodeSegment>();

            IList <RegexDecoderDefinition> definitions = decoderDefinitions.ToList();

            string[] split = text.Split((char)fnc1);

            for (int i = 0; i < split.Length; i++)
            {
                string textPart   = split[i];
                bool   matchFound = true;

                while (matchFound)
                {
                    matchFound = false;

                    foreach (RegexDecoderDefinition definition in definitions)
                    {
                        Match match = definition.Regex.Match(textPart);

                        if (match.Success && (!string.IsNullOrEmpty(match.Value)))
                        {
                            bool decimalPointIndicator = false;

                            BarcodeSegment segment = new BarcodeSegment();

                            string AI = string.Empty;

                            if (definition.ApplicationIdentifier.EndsWith("y"))
                            {
                                decimalPointIndicator = true;
                                AI = definition.ApplicationIdentifier.Replace("y", "");
                            }
                            else
                            {
                                AI = definition.ApplicationIdentifier;
                            }

                            segment.ApplicationIdentifier     = definition.ApplicationIdentifier;
                            segment.ApplicationIdentifierName = definition.ApplicationIdentifierName;


                            int start = 0;

                            if (match.Value[0] == fnc1)
                            {
                                start++;
                            }

                            if (!string.IsNullOrEmpty(segment.ApplicationIdentifier))
                            {
                                if (definition.Regex.ToString().IndexOf(AI) > -1 && definition.Regex.ToString().IndexOf(AI) < 2)
                                {
                                    start += AI.Length;
                                }
                            }

                            string data = match.Value.Substring(start);

                            if (decimalPointIndicator)
                            {
                                int decimals = Convert.ToInt32(data.Substring(0, 1));
                                data = data.Substring(1, (data.Length - (decimals + 1))) + System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator + data.Substring(data.Length - decimals);
                            }

                            segment.Text = data;

                            textPart = textPart.Remove(match.Index, match.Length);

                            segments.Add(segment);

                            matchFound = true;

                            break;
                        }
                    }
                }
            }

            return(segments);
        }