Exemplo n.º 1
0
        /// <summary>
        /// 根据机内格式 MARC 字符串,创建若干 MarcField (或 MarcOuterField) 对象
        /// </summary>
        /// <param name="strText">MARC 机内格式字符串</param>
        /// <param name="strOuterFieldDef">嵌套字段的定义。缺省为 null,表示不使用嵌套字段。这是一个列举字段名的逗号间隔的列表('*'为通配符),或者 '@' 字符后面携带一个正则表达式</param>
        /// <returns>新创建的 MarcField 对象集合</returns>
        public static MarcNodeList createFields(
            string strText,
            string strOuterFieldDef = null)
        {
            MarcNodeList results = new MarcNodeList();

            List <string> segments   = new List <string>();
            StringBuilder field_text = new StringBuilder(4096);

            for (int i = 0; i < strText.Length; i++)
            {
                char ch = strText[i];
                if (ch == 30 || ch == 29)
                {
                    // 上一个字段结束
                    segments.Add(field_text.ToString());
                    field_text.Clear();
                }
                else
                {
                    field_text.Append(ch);
                }
            }

            // 剩余的内容
            if (field_text.Length > 0)
            {
                segments.Add(field_text.ToString());
                field_text.Clear();
            }

            foreach (string segment in segments)
            {
                string strSegment = segment;

                // 如果长度不足 3 字符,补齐?
                if (strSegment.Length < 3)
                {
                    strSegment = strSegment.PadRight(3, '?');
                }

                // 创建头标区以后的普通字段
                MarcNode field = null;
                if (string.IsNullOrEmpty(strOuterFieldDef) == false)
                {
                    string strFieldName = strSegment.Substring(0, 3);
                    // return:
                    //		-1	error
                    //		0	not match
                    //		1	match
                    int nRet = MatchName(strFieldName,
                                         strOuterFieldDef);
                    if (nRet == 1)
                    {
                        field = new MarcOuterField();
                    }
                    else
                    {
                        field = new MarcField();
                    }
                }
                else
                {
                    field = new MarcField();
                }


                field.Text = strSegment;
                results.add(field);
                // Debug.Assert(field.Parent == parent, "");
            }

            return(results);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据机内格式 MARC 字符串,创建若干 MarcField (或 MarcOuterField) 对象
        /// </summary>
        /// <param name="strText">MARC 机内格式字符串</param>
        /// <param name="strOuterFieldDef">嵌套字段的定义。缺省为 null,表示不使用嵌套字段。这是一个列举字段名的逗号间隔的列表('*'为通配符),或者 '@' 字符后面携带一个正则表达式</param>
        /// <returns>新创建的 MarcField 对象集合</returns>
        public static MarcNodeList createFields(
            string strText,
            string strOuterFieldDef = null)
        {
            MarcNodeList results = new MarcNodeList();

            List<string> segments = new List<string>();
            StringBuilder field_text = new StringBuilder(4096);
            for (int i = 0; i < strText.Length; i++)
            {
                char ch = strText[i];
                if (ch == 30 || ch == 29)
                {
                    // 上一个字段结束
                    segments.Add(field_text.ToString());
                    field_text.Clear();
                }
                else
                {
                    field_text.Append(ch);
                }
            }

            // 剩余的内容
            if (field_text.Length > 0)
            {
                segments.Add(field_text.ToString());
                field_text.Clear();
            }

            foreach (string segment in segments)
            {
                string strSegment = segment;

                // 如果长度不足 3 字符,补齐?
                if (strSegment.Length < 3)
                    strSegment = strSegment.PadRight(3, '?');

                // 创建头标区以后的普通字段
                MarcNode field = null;
                if (string.IsNullOrEmpty(strOuterFieldDef) == false)
                {
                    string strFieldName = strSegment.Substring(0, 3);
                    // return:
                    //		-1	error
                    //		0	not match
                    //		1	match
                    int nRet = MatchName(strFieldName,
                        strOuterFieldDef);
                    if (nRet == 1)
                        field = new MarcOuterField();
                    else
                        field = new MarcField();
                }
                else
                    field = new MarcField();


                field.Text = strSegment;
                results.add(field);
                // Debug.Assert(field.Parent == parent, "");
            }

            return results;
        }