예제 #1
0
        /// <summary>
        /// Compares the specified sub field1.
        /// </summary>
        /// <param name="subField1">The sub field1.</param>
        /// <param name="subField2">The sub field2.</param>
        /// <param name="verbose">if set to <c>true</c> [verbose].</param>
        /// <returns>System.Int32.</returns>
        public static int Compare
        (
            SubField subField1,
            SubField subField2,
            bool verbose
        )
        {
            int result = subField1.Code.CompareTo(subField2.Code);

            if (result != 0)
            {
                if (verbose)
                {
                    Console.WriteLine
                    (
                        "SubField1 Code={0}, SubField2 Code={1}",
                        subField1.Code,
                        subField2.Code
                    );
                }
                return(result);
            }

            result = string.CompareOrdinal(subField1.Text, subField2.Text);
            if (verbose && (result != 0))
            {
                Console.WriteLine
                (
                    "SubField1 Text={0}, SubField2 Text={1}",
                    subField1.Text,
                    subField2.Text
                );
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Установка подполя.
        /// </summary>
        public IrbisRecord SetSubField
        (
            string tag,
            int fieldOccurrence,
            char code,
            int subFieldOccurrence,
            string newText
        )
        {
            RecordField field = Fields
                                .GetField(tag)
                                .GetOccurrence(fieldOccurrence);

            if (!ReferenceEquals(field, null))
            {
                SubField subField = field.GetSubField
                                    (
                    code,
                    subFieldOccurrence
                                    );
                if (!ReferenceEquals(subField, null))
                {
                    subField.Text = newText;
                }
            }

            return(this);
        }
예제 #3
0
        private static RecordField _ParseLine
        (
            string line
        )
        {
            StringReader reader = new StringReader(line);

            RecordField result = new RecordField
            {
                Tag  = _ReadTo(reader, '#'),
                Text = _ReadTo(reader, '^')
            };

            while (true)
            {
                int next = reader.Read();
                if (next < 0)
                {
                    break;
                }
                char     code     = char.ToLower((char)next);
                string   text     = _ReadTo(reader, '^');
                SubField subField = new SubField
                {
                    Code = code,
                    Text = text
                };
                result.SubFields.Add(subField);
            }

            return(result);
        }
예제 #4
0
 public static string GetSubFieldText
 (
     this SubField subField
 )
 {
     return((subField == null)
                ? null
                : subField.Text);
 }
예제 #5
0
 public static string GetSubFieldText
 (
     [CanBeNull] this SubField subField
 )
 {
     return(ReferenceEquals(subField, null)
                ? null
                : subField.Text);
 }
예제 #6
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns></returns>
        public SubField Clone( )
        {
            SubField result = new SubField
            {
                Code = Code,
                Text = Text
            };

            return(result);
        }
예제 #7
0
        public void ExportSubField
        (
            XmlWriter writer,
            SubField subField
        )
        {
            string localName = "SUBFIELD." + char.ToUpper(subField.Code);

            writer.WriteElementString(localName, subField.Text);
        }
예제 #8
0
        public string GetFirstSubFieldText
        (
            char code
        )
        {
            SubField result = GetFirstSubField(code);

            return((result == null)
                ? null
                : result.Text);
        }
예제 #9
0
        /// <summary>
        /// Получение текста указанного подполя.
        /// </summary>
        /// <param name="code">Искомый код подполя.</param>
        /// <param name="occurrence">Номер повторения.
        /// Нумерация начинается с нуля.
        /// Отрицательные индексы отсчитываются с конца массива.</param>
        /// <returns>Текст найденного подполя или <c>null</c>.</returns>
        public string GetSubFieldText
        (
            char code,
            int occurrence
        )
        {
            SubField result = GetSubField(code, occurrence);

            return((result == null)
                       ? null
                       : result.Text);
        }
예제 #10
0
 private static void _EncodeSubField
 (
     StringBuilder builder,
     SubField subField
 )
 {
     builder.AppendFormat
     (
         "^{0}{1}",
         subField.Code,
         subField.Text
     );
 }
예제 #11
0
        /// <summary>
        /// Sets the sub field.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        /// <remarks>Устанавливает значение только первого
        /// подполя с указанным кодом (если в поле их несколько)!
        /// </remarks>
        public RecordField SetSubField
        (
            char code,
            string text
        )
        {
            SubField subField = SubFields
                                .Find(_ => _.Code.SameChar(code));

            if (subField == null)
            {
                subField = new SubField(code, text);
                SubFields.Add(subField);
            }
            subField.Text = text;
            return(this);
        }
예제 #12
0
        /// <summary>
        /// Sets the sub field.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        /// <remarks>Устанавливает значение только первого
        /// подполя с указанным кодом (если в поле их несколько)!
        /// </remarks>
        public RecordField SetSubField
        (
            char code,
            string text
        )
        {
            code = char.ToLowerInvariant(code);
            SubField subField = SubFields
                                .Find(_ => char.ToLowerInvariant(_.Code) == code);

            if (subField == null)
            {
                subField = new SubField(code, text);
                SubFields.Add(subField);
            }
            subField.Text = text;
            return(this);
        }
예제 #13
0
        /// <summary>
        /// Указанное повторение подполя с данным кодом.
        /// </summary>
        /// <param name="code">Искомый код подполя.</param>
        /// <param name="occurrence">Номер повторения.
        /// Нумерация начинается с нуля.
        /// Отрицательные индексы отсчитываются с конца массива.</param>
        /// <returns>Найденное подполе или <c>null</c>.</returns>
        public SubField GetSubField
        (
            char code,
            int occurrence
        )
        {
            SubField[] found = GetSubField(code);
            occurrence = (occurrence >= 0)
                            ? occurrence
                            : found.Length - occurrence;
            SubField result = null;

            if ((occurrence >= 0) && (occurrence < found.Length))
            {
                result = found[occurrence];
            }
            return(result);
        }
예제 #14
0
        public static IrbisRecord ReadIso
        (
            Stream strm,
            Encoding enc
        )
        {
            IrbisRecord result = new IrbisRecord();

            byte[] marker = new byte[5];

            // Считываем длину записи
            if (strm.Read(marker, 0, 5) != 5)
            {
                return(null);
            }
            int reclen = _ToInt(marker, 0, 5);

            byte[] record = new byte[reclen];
            int    need   = reclen - 5;

            // А затем и ее остаток
            if (strm.Read(record, 5, need) != need)
            {
                return(null);
            }

            // простая проверка, что мы имеем дело с нормальной ISO-записью
            if (record[reclen - 1] != RecordDelimiter)
            {
                return(null);
            }

            // Превращаем в Unicode
            char[] chars       = enc.GetChars(record, 0, reclen);
            int    baseAddress = _ToInt(record, 12, 5) - 1;
            int    start       = baseAddress;

            // Пошли по полям (при помощи словаря)
            for (int dic = MarkerLength; ; dic += 12)
            {
                // находим следующее поле
                // Если нарвались на разделитель, заканчиваем
                if ((record[dic] == FieldDelimiter) ||
                    (start > (reclen - 4)))
                {
                    break;
                }
                string      tag     = new string(chars, dic, 3);
                RecordField fld     = new RecordField(tag);
                bool        isFixed = tag.StartsWith("00");
                result.Fields.Add(fld);
                start++;
                int end;
                if (isFixed)
                {
                    for (end = start; ; end++)
                    {
                        if (record[end] == FieldDelimiter)
                        {
                            break;
                        }
                    }
                    fld.Text = new string(chars, start, end - start);
                    start    = end;
                }
                else
                {
                    start += 2;
                    while (true)
                    {
                        // находим подполя
                        if (record[start] == FieldDelimiter)
                        {
                            break;
                        }
                        if (record[start] != SubfieldDelimiter)
                        {
                            // Нарвались на поле без подполей
                            for (end = start; ; end++)
                            {
                                if ((record[end] == FieldDelimiter) ||
                                    (record[end] == SubfieldDelimiter))
                                {
                                    break;
                                }
                            }
                            fld.Text = new string
                                       (chars,
                                        start,
                                        end - start);
                        }
                        else
                        {
                            // Декодируем подполя
                            SubField sub = new SubField
                                               (chars[++start]);
                            fld.SubFields.Add(sub);
                            start++;
                            for (end = start; ; end++)
                            {
                                if ((record[end] == FieldDelimiter) ||
                                    (record[end] == SubfieldDelimiter))
                                {
                                    break;
                                }
                            }
                            sub.Text = new string
                                       (chars,
                                        start,
                                        end - start);
                        }
                        start = end;
                    }
                }
            }

            return(result);
        }
예제 #15
0
        public static int Compare
        (
            RecordField field1,
            RecordField field2,
            bool verbose
        )
        {
            int result = string.CompareOrdinal(field1.Tag, field2.Tag);

            if (result != 0)
            {
                if (verbose)
                {
                    Console.WriteLine
                    (
                        "Field1 Tag={0}, Field2 Tag={1}",
                        field1.Tag,
                        field2.Tag
                    );
                }
                return(result);
            }

            if (!string.IsNullOrEmpty(field1.Text) ||
                !string.IsNullOrEmpty(field2.Text))
            {
                result = string.CompareOrdinal(field1.Text, field2.Text);
                if (result != 0)
                {
                    if (verbose)
                    {
                        Console.WriteLine
                        (
                            "Field1 Text={0}, Field2 Text={1}",
                            field1.Text,
                            field2.Text
                        );
                    }
                    return(result);
                }
            }

            IEnumerator <SubField> enum1 = field1.SubFields.GetEnumerator();
            IEnumerator <SubField> enum2 = field2.SubFields.GetEnumerator();

            while (true)
            {
                bool next1 = enum1.MoveNext();
                bool next2 = enum2.MoveNext();

                if ((!next1) && (!next2))
                {
                    break;
                }
                if (!next1)
                {
                    return(-1);
                }
                if (!next2)
                {
                    return(1);
                }

                SubField subField1 = enum1.Current;
                SubField subField2 = enum2.Current;

                result = SubField.Compare
                         (
                    subField1,
                    subField2,
                    verbose
                         );
                if (result != 0)
                {
                    return(result);
                }
            }

            return(0);
        }