/// <summary> /// Parses a dictionary from the current parsing position. /// The prerequisite for calling this method is, that a dictionary begin token has been read. /// </summary> /// <returns>The dictionary found at the parsing position.</returns> NSDictionary ParseDictionary() { //Skip begin token var origin = new BinaryOrigin(this.index, 0); Skip(); SkipWhitespacesAndComments(); NSDictionary dict = new NSDictionary(origin); while (!Accept(DICTIONARY_END_TOKEN)) { //Parse key string keyString; if (Accept(QUOTEDSTRING_BEGIN_TOKEN)) { keyString = ParseQuotedString(); } else { keyString = ParseString(); } SkipWhitespacesAndComments(); //Parse assign token Read(DICTIONARY_ASSIGN_TOKEN); SkipWhitespacesAndComments(); NSObject nso = ParseObject(); dict.Add(keyString, nso); SkipWhitespacesAndComments(); Read(DICTIONARY_ITEM_DELIMITER_TOKEN); SkipWhitespacesAndComments(); } //skip end token Skip(); origin.SetEndPosition(this.index); return(dict); }
/// <summary> /// Parses a data object from the current parsing position. /// This can either be a NSData object or a GnuStep NSNumber or NSDate. /// The prerequisite for calling this method is, that a data begin token has been read. /// </summary> /// <returns>The data object found at the parsing position.</returns> NSObject ParseData() { NSObject obj = null; //Skip begin token var origin = new BinaryOrigin(this.index, 0); Skip(); if (Accept(DATA_GSOBJECT_BEGIN_TOKEN)) { Skip(); Expect(DATA_GSBOOL_BEGIN_TOKEN, DATA_GSDATE_BEGIN_TOKEN, DATA_GSINT_BEGIN_TOKEN, DATA_GSREAL_BEGIN_TOKEN); if (Accept(DATA_GSBOOL_BEGIN_TOKEN)) { //Boolean Skip(); Expect(DATA_GSBOOL_TRUE_TOKEN, DATA_GSBOOL_FALSE_TOKEN); if (Accept(DATA_GSBOOL_TRUE_TOKEN)) { obj = new NSNumber(true, origin); } else { obj = new NSNumber(false, origin); } //Skip the parsed boolean token Skip(); } else if (Accept(DATA_GSDATE_BEGIN_TOKEN)) { //Date Skip(); string dateString = ReadInputUntil(DATA_END_TOKEN); obj = new NSDate(dateString, origin); } else if (Accept(DATA_GSINT_BEGIN_TOKEN, DATA_GSREAL_BEGIN_TOKEN)) { //Number Skip(); string numberString = ReadInputUntil(DATA_END_TOKEN); obj = new NSNumber(numberString, origin); } //parse data end token Read(DATA_END_TOKEN); } else { string dataString = ReadInputUntil(DATA_END_TOKEN); dataString = Regex.Replace(dataString, "\\s+", ""); int numBytes = dataString.Length / 2; byte[] bytes = new byte[numBytes]; for (int i = 0; i < bytes.Length; i++) { string byteString = dataString.Substring(i * 2, 2); int byteValue = Convert.ToInt32(byteString, 16); bytes[i] = (byte)byteValue; } obj = new NSData(bytes, origin); //skip end token Skip(); } origin.SetEndPosition(this.index); return(obj); }