Пример #1
0
        /// <summary>
        /// Parses an array from the current parsing position.
        /// The prerequisite for calling this method is, that an array begin token has been read.
        /// </summary>
        /// <returns>The array found at the parsing position.</returns>
        NSArray ParseArray()
        {
            //Skip begin token
            int startPosition = this.index;

            Skip();
            SkipWhitespacesAndComments();
            List <NSObject> objects = new List <NSObject>();

            while (!Accept(ARRAY_END_TOKEN))
            {
                objects.Add(ParseObject());
                SkipWhitespacesAndComments();
                if (Accept(ARRAY_ITEM_DELIMITER_TOKEN))
                {
                    Skip();
                }
                else
                {
                    break; //must have reached end of array
                }
                SkipWhitespacesAndComments();
            }
            //parse end token
            Read(ARRAY_END_TOKEN);
            return(new NSArray(objects.ToArray(), BinaryOrigin.FromRange(startPosition, this.index)));
        }
Пример #2
0
        /// <summary>
        /// Parses the NSObject found at the current position in the property list
        /// data stream.
        /// </summary>
        /// <returns>The parsed NSObject.</returns>
        /// <seealso cref="ASCIIPropertyListParser.index"/>
        NSObject ParseObject()
        {
            switch (data[index])
            {
            case ARRAY_BEGIN_TOKEN:
            {
                return(ParseArray());
            }

            case DICTIONARY_BEGIN_TOKEN:
            {
                return(ParseDictionary());
            }

            case DATA_BEGIN_TOKEN:
            {
                return(ParseData());
            }

            case QUOTEDSTRING_BEGIN_TOKEN:
            {
                int    startIndex   = this.index;
                string quotedString = ParseQuotedString();
                //apple dates are quoted strings of length 20 and after the 4 year digits a dash is found
                if (quotedString.Length == 20 && quotedString[4] == DATE_DATE_FIELD_DELIMITER)
                {
                    try
                    {
                        return(new NSDate(quotedString, BinaryOrigin.FromRange(startIndex, this.index)));
                    }
                    catch (Exception)
                    {
                        //not a date? --> return string
                        return(new NSString(quotedString, BinaryOrigin.FromRange(startIndex, this.index)));
                    }
                }
                return(new NSString(quotedString, BinaryOrigin.FromRange(startIndex, this.index)));
            }

            default:
            {
                //0-9
                if (data[index] > 0x2F && data[index] < 0x3A)
                {
                    //could be a date or just a string
                    return(ParseDateString());
                }
                else
                {
                    //non-numerical -> string or boolean
                    var    startIndex   = this.index;
                    string parsedString = ParseString();
                    return(new NSString(parsedString, BinaryOrigin.FromRange(startIndex, this.index)));
                }
            }
            }
        }
Пример #3
0
        /// <summary>
        /// Attempts to parse a plain string as a date if possible.
        /// </summary>
        /// <returns>A NSDate if the string represents such an object. Otherwise a NSString is returned.</returns>
        NSObject ParseDateString()
        {
            var    startIndex      = this.index;
            string numericalString = ParseString();

            if (numericalString.Length > 4 && numericalString[4] == DATE_DATE_FIELD_DELIMITER)
            {
                try
                {
                    return(new NSDate(numericalString, BinaryOrigin.FromRange(startIndex, this.index)));
                }
                catch (Exception)
                {
                    //An exception occurs if the string is not a date but just a string
                }
            }
            return(new NSString(numericalString, BinaryOrigin.FromRange(startIndex, this.index)));
        }