Esempio n. 1
0
 public static IEnumerable <int> GetLines(Stream str, List <string> segs, TextReaderOptions options)
 {
     using (LineReader r = new LineReader(str, options)) {
         return(r.GetLines(segs, 1));
     }
 }
Esempio n. 2
0
            public void Load(LineReader reader)
            {
                Dictionary <int, string> alternativeNames = _owner.AlternativeNames;
                List <string>            segs             = new List <string>();
                int          firstRange = 0;
                int          lastRange  = 0;
                const string FirstRange = ", First>";
                const string LastRange  = ", Last>";

                foreach (var count in reader.GetLines(segs, 15))
                {
                    if (count != 15)
                    {
                        continue;
                    }

                    _entry = new UnicodeEntry();
                    if (!TryParseHex(segs[0], out _entry.CodeValue))
                    {
                        continue;
                    }


                    if (_entry.CodeValue > _owner._maxCodePoint)
                    {
                        break;
                    }
                    string name = segs[1];
                    string dscr;
                    if ((Options & LoadOptions.AlternativeNames) != 0 &&
                        alternativeNames.TryGetValue(_entry.CodeValue, out dscr))
                    {
                        name = dscr;
                    }
                    else
                    {
                        dscr = name;
                        if (name.HasValue())
                        {
                            if (name[0] == '<')
                            {
                                if (name.SameName("<control>"))
                                {
                                    dscr = segs[10];
                                }
                                else if (name.EndsWith(FirstRange, StringComparison.OrdinalIgnoreCase))
                                {
                                    firstRange = _entry.CodeValue;
                                    name       = name.Substring(1, name.Length - 1 - FirstRange.Length);
                                    dscr       = null;
                                }
                                else if (name.EndsWith(LastRange, StringComparison.OrdinalIgnoreCase))
                                {
                                    name      = name.Substring(1, name.Length - 1 - LastRange.Length);
                                    dscr      = null;
                                    lastRange = _entry.CodeValue;
                                }
                                else
                                {
                                    Debug.WriteLine("Asd:" + name);
                                }
                            }
                        }
                    }

                    if (dscr.HasValue())
                    {
                        if ((Options & LoadOptions.EnumNames) != 0)
                        {
                            _entry.EnumName = Util.GenEnumName(dscr);
                        }
                    }
                    else if (!alternativeNames.TryGetValue(_entry.CodeValue, out dscr))
                    {
                        //Debug.WriteLine( "NO NAME " + _entry.CodeValue.ToString( "X4" ) + " " + segs[ 11 ] );
                    }
                    _entry.Name = name;
                    if (!_charTypes.TryGetValue(segs[2], out _entry.Category))
                    {
                        Error("Unknown category '{0}'", segs[2]);
                    }
                    byte comb;
                    if (!byte.TryParse(segs[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out comb))
                    {
                        Error("Unknown combing class '{0}'", segs[3]);
                    }
                    _entry.Combing = (CombingClass)comb;

                    if (!_bidiMap.TryGetValue(segs[4], out _entry.Bidirectional))
                    {
                        Error("Unknown bidi category '{0}'", segs[4]);
                    }
                    if (_decomposeMap != null && !string.IsNullOrEmpty(segs[5]))
                    {
                        ParseDecombosing(segs[5]);
                    }
                    //_entry._numericType = NumericEntryType.None;
                    byte dec;

                    if (segs[6].Length > 0)
                    {
                        if (!byte.TryParse(segs[6], NumberStyles.Integer,
                                           CultureInfo.InvariantCulture, out dec) ||
                            dec > 9)
                        {
                            Error("Invalid Decimal digit value '{0}'", segs[6]);
                        }
                        _entry._numericType = NumericEntryType.Decimal;
                        _entry._value.Value = dec;
                        //_Decimals.Increment( _entry.DecimalValue );
                    }
                    if (segs[7].Length > 0)
                    {
                        if (!byte.TryParse(segs[7], NumberStyles.Integer,
                                           CultureInfo.InvariantCulture, out dec) ||
                            dec > 9)
                        {
                            Error("Invalid Digit value '{0}'", segs[7]);
                        }
                        if (!_entry.IsDecimalDigit)
                        {
                            _entry._numericType = NumericEntryType.Digit;
                            _entry._value.Value = dec;
                        }
                        else if (_entry._value.Value != dec)
                        {
                            Error("Invalid Digit value '{0}'", segs[7]);
                        }
                    }
                    else if (_entry._numericType != NumericEntryType.None)
                    {
                        Error("Invalid Digit value '{0}'", segs[7]);
                    }
                    if (segs[8].Length > 0)
                    {
                        ParseNumeric(segs[8]);
                    }
                    switch (segs[9])
                    {
                    case "":
                    case "N":
                        break;

                    case "Y":
                        _entry.Mirrored = true;
                        break;

                    default:
                        Error("Invalid Mirrored value '{0}'", segs[9]);
                        break;
                    }
                    if ((Options & LoadOptions.OldNames) != 0 &&
                        segs[10].Length > 0)
                    {
                        _entry.OldName = segs[10];
                    }
                    if ((Options & LoadOptions.Comments) != 0 &&
                        segs[11].Length > 0)
                    {
                        _entry.Comment = segs[11];
                    }
                    if (segs[12].Length > 0)
                    {
                        if (!TryParseHex(segs[12], out _entry.Uppercase))
                        {
                            Error("Invlaid code point '{0}'", segs[12]);
                        }
                    }
                    if (segs[13].Length > 0)
                    {
                        if (!TryParseHex(segs[13], out _entry.LowerCase))
                        {
                            Error("Invlaid code point '{0}'", segs[13]);
                        }
                    }
                    if (segs[14].Length > 0)
                    {
                        if (!TryParseHex(segs[14], out _entry.TitleCase))
                        {
                            Error("Invlaid code point '{0}'", segs[14]);
                        }
                    }
                    if (lastRange > 0)
                    {
                        _entry.CodeValue = firstRange + 1;
                        while (_entry.CodeValue < lastRange)
                        {
                            Add(_entry);
                            _entry.CodeValue++;
                        }
                        lastRange  = 0;
                        firstRange = 0;
                    }
                    Add(_entry);
                }
                //ShowCounts();
            }