Beispiel #1
0
        /// <summary>
        /// Parses the input string into a valid HfaField, or returns null
        /// if one could not be created.
        /// </summary>
        /// <param name="input">The input string.</param>
        /// <returns>The parsed string, or null if the field could not be created.</returns>
        public string Initialize(string input)
        {
            int length = input.Length;
            int start  = 0;

            // Read the number
            if (!input.Contains(":"))
            {
                return(null);
            }

            ItemCount = short.Parse(input.ExtractTo(ref start, ":"));

            // is this a pointer?
            if (input[start] == 'p' || input[start] == '*')
            {
                start  += 1;
                Pointer = input[start];
            }

            // Get the general type
            start += 1;
            if (start == length)
            {
                return(null);
            }

            ItemType = input[start];
            if (!"124cCesStlLfdmMbox".Contains(ItemType.ToString()))
            {
                throw new HfaFieldTypeException(ItemType);
            }

            // If this is an object, we extract the type of the object
            if (ItemType == 'o')
            {
                ItemObjectTypeString = input.ExtractTo(ref start, ",");
            }

            // If this is an inline object, we need to skip past the
            // definition, and then extract the object class name.
            // we ignore the actual definition, so if the object type isn't
            // already defined, things will not work properly. See the
            // file lceugr250)00)pct.aus for an example of inline defs.
            if (ItemType == 'x' && input[start] == '{')
            {
                int braceDepth = 1;
                start += 1;

                // Skip past the definition in braces
                while (braceDepth > 0 && start < input.Length)
                {
                    if (input[start] == '{')
                    {
                        braceDepth++;
                    }
                    if (input[start] == '}')
                    {
                        braceDepth--;
                    }
                    start++;
                }

                ItemType             = 'o';
                ItemObjectTypeString = input.ExtractTo(ref start, ",");
            }

            // If this is an enumeration, we have to extract all the values.
            if (ItemType == 'e')
            {
                if (!input.Contains(":"))
                {
                    return(null);
                }

                int enumCount = int.Parse(input.ExtractTo(ref start, ":"));
                if (EnumNames == null)
                {
                    EnumNames = new List <string>();
                }
                for (int ienum = 0; ienum < enumCount; ienum++)
                {
                    EnumNames.Add(input.ExtractTo(ref start, ","));
                }
            }

            // Extract the field name
            FieldName = input.ExtractTo(ref start, ",");

            // Return whatever is left in the string, which should be a new field.
            return(input.Substring(start, input.Length - start));
        }