public static PDFDictionary ParseDictionary(string value, int offset, out int end) { AssertValidValue(value, offset + 1); if (value[offset] != DictionaryStartChar) { throw new PDFNativeParserException(CommonErrors.DictionaryDoesNotStartWithRequiredChar); } if (value[offset + 1] != DictionaryStartChar) { throw new PDFNativeParserException(CommonErrors.DictionaryDoesNotStartWithRequiredChar); } PDFDictionary dict = new PDFDictionary(); offset += 2; while (offset < value.Length) { char c = value[offset]; if (char.IsWhiteSpace(c)) { offset++; } else if (c == NameStartCharacter) { PDFName name = ParseName(value, offset, out end); offset = end; IFileObject obj = InferAndParseNextObject(value, offset, out end); dict[name] = obj; offset = end; } else if (c == DictionaryEndChar) { if (value.Length > offset + 1 && value[offset + 1] == DictionaryEndChar) { offset += 2; break; } else { throw new PDFNativeParserException(CommonErrors.DictionaryDoesNotEndWithRequiredChar); } } else { throw new PDFNativeParserException(CommonErrors.AllDictionaryKeysMustBePDFNames); } } end = offset; return(dict); }
protected static PDFObjectRef AssertGetObjectRef(PDFDictionary dict, PDFName entry, string errorMessage) { IFileObject found; if (!dict.TryGetValue(entry, out found)) { throw new PDFNativeParserException(errorMessage); } if (found.Type != PDFObjectTypes.ObjectRef) { throw new PDFNativeParserException(errorMessage); } return((PDFObjectRef)found); }