示例#1
0
        public static string GetSubFieldValue
        (
            this RecordField field,
            char code,
            int occurrence
        )
        {
            SubField result = field.GetSubField
                              (
                code,
                occurrence
                              );

            return(ReferenceEquals(result, null)
                ? null
                : result.Value);
        }
示例#2
0
        // ==========================================================

        public static bool HaveSubField
        (
            this RecordField field,
            char code
        )
        {
            SubFieldCollection subFields = field.SubFields;
            int count = subFields.Length;

            for (int i = 0; i < count; i++)
            {
                if (Utility.SameChar(subFields[i].Code, code))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#3
0
        public static bool HaveSubField
        (
            this RecordField field,
            params char[] codes
        )
        {
            SubFieldCollection subFields = field.SubFields;
            int count = subFields.Length;

            for (int i = 0; i < count; i++)
            {
                if (Utility.OneOf(subFields[i].Code, codes))
                {
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
        public static RecordField SetSubField
        (
            this RecordField field,
            char code,
            string value
        )
        {
            SubField subField = field.SubFields
                                .Cast <SubField>()
                                .FirstOrDefault(sub => Utility.SameChar(code, sub.Code));

            if (ReferenceEquals(subField, null))
            {
                subField = new SubField {
                    Code = code
                };
                field.SubFields.Add(subField);
            }
            subField.Value = value;
            return(field);
        }
示例#5
0
        internal static void ParseSingle(MarcRecord record,
                                         string[] text)
        {
            char[] delimiters = { '#' };
            string line       = text[0];

            string[] parts = Utility.SplitString(delimiters, line);
            record.Mfn = int.Parse(parts[0]);
            if (parts.Length != 1)
            {
                record.Status = int.Parse(parts[1]);
            }
            line           = text[1];
            parts          = line.Split(delimiters);
            record.Version = int.Parse(parts[1]);
            for (int i = 2; i < text.Length; i++)
            {
                RecordField field = RecordField.Parse(text[i]);
                record.Fields.Add(field);
            }
        }
示例#6
0
        public static RecordField ReplaceSubField
        (
            this RecordField field,
            char code,
            string oldValue,
            string newValue
        )
        {
            var found = field.SubFields
                        .Cast <SubField>()
                        .Where
                        (
                subField => Utility.SameChar(code, subField.Code) &&
                Utility.SameString(oldValue, subField.Value)
                        );

            foreach (SubField subField in found)
            {
                subField.Value = newValue;
            }
            return(field);
        }
示例#7
0
        internal static RecordField Parse(string line)
        {
            StringReader reader = new StringReader(line);
            RecordField  result
                = new RecordField(Utility.ReadTo(reader, '#'));

            result.Value = Utility.ReadTo(reader, '^');
            while (true)
            {
                int next = reader.Read();
                if (next < 0)
                {
                    break;
                }
                char     code     = char.ToLower((char)next);
                string   value    = Utility.ReadTo(reader, '^');
                SubField subField = new SubField();
                subField.Code  = code;
                subField.Value = value;
                result.SubFields.Add(subField);
            }
            return(result);
        }
示例#8
0
        public static SubField GetSubField
        (
            this RecordField field,
            char code,
            int occurrence
        )
        {
            SubFieldCollection subFields = field.SubFields;
            int count = subFields.Length;

            for (int i = 0; i < count; i++)
            {
                if (Utility.SameChar(subFields[i].Code, code))
                {
                    if (occurrence == 0)
                    {
                        return(subFields[i]);
                    }
                    occurrence--;
                }
            }

            return(null);
        }
示例#9
0
 public void Remove(RecordField item)
 {
     _list.Remove(item);
 }
示例#10
0
 public void Add(RecordField item)
 {
     _list.Add(item);
 }