コード例 #1
0
 public static Annotations FromProtoAnnotations(StringPool stringPool, SkylineDocumentProto.Types.Annotations protoAnnotations)
 {
     Assume.IsNotNull(stringPool);
     if (protoAnnotations == null)
     {
         return(EMPTY);
     }
     return(new Annotations(protoAnnotations.Note, protoAnnotations.Values
                            .Select(value => new KeyValuePair <string, string>(
                                        stringPool.GetString(value.Name),
                                        stringPool.GetString(value.TextValue))),
                            protoAnnotations.Color));
 }
コード例 #2
0
 public override string ToString()
 {
     return(StringPool.GetString(this));
 }
コード例 #3
0
        /// <summary>
        /// Advances to the next parsing event and returns its type. See <code>EVENT_...</code> constants.
        /// </summary>
        /// <returns></returns>
        public int Next()
        {
            // Decrement depth if the previous event was "end element".
            if (EventType == EventEndElement)
            {
                Depth--;
            }
            // Read events from document, ignoring events that we don't report to caller. Stop at the
            // earliest event which we report to caller.
            while (_xml.BaseStream.Remaining() > 0)
            {
                Chunk chunk = Chunk.Get(_xml);
                if (chunk == null)
                {
                    break;
                }
                switch (chunk.Type)
                {
                case Chunk.TypeStringPool:
                    if (_stringPool != null)
                    {
                        throw new FormatException("Multiple string pools not supported");
                    }
                    _stringPool = new StringPool(chunk);
                    break;

                case Chunk.ResXmlTypeStartElement:
                {
                    if (_stringPool == null)
                    {
                        throw new FormatException(
                                  "Named element encountered before string pool");
                    }
                    var contents = chunk.Contents;
                    if (contents.Length < 20)
                    {
                        throw new FormatException(
                                  "Start element chunk too short. Need at least 20 bytes. Available: "
                                  + contents.Length + " bytes");
                    }
                    var  contentReader   = new BinaryReader(new MemoryStream(contents));
                    long nsId            = contentReader.ReadUInt32();
                    long nameId          = contentReader.ReadUInt32();
                    int  attrStartOffset = contentReader.ReadUInt16();
                    int  attrSizeBytes   = contentReader.ReadUInt16();
                    int  attrCount       = contentReader.ReadUInt16();
                    long attrEndOffset   = attrStartOffset + ((long)attrCount) * attrSizeBytes;
                    contentReader.BaseStream.Position = 0;
                    if (attrStartOffset > contents.Length)
                    {
                        throw new FormatException(
                                  "Attributes start offset out of bounds: " + attrStartOffset
                                  + ", max: " + contents.Length);
                    }
                    if (attrEndOffset > contents.Length)
                    {
                        throw new FormatException(
                                  "Attributes end offset out of bounds: " + attrEndOffset
                                  + ", max: " + contents.Length);
                    }
                    Name      = _stringPool.GetString(nameId);
                    Namespace =
                        (nsId == NoNamespace) ? "" : _stringPool.GetString(nsId);
                    AttributeCount                    = attrCount;
                    _currentElementAttributes         = null;
                    _currentElementAttrSizeBytes      = attrSizeBytes;
                    _currentElementAttributesContents =
                        SliceFromTo(contentReader.BaseStream, attrStartOffset, attrEndOffset);
                    Depth++;
                    return(EventType = EventStartElement);
                }

                case Chunk.ResXmlTypeEndElement:
                {
                    if (_stringPool == null)
                    {
                        throw new FormatException(
                                  "Named element encountered before string pool");
                    }
                    var contents = chunk.Contents;
                    if (contents.Length < 8)
                    {
                        throw new FormatException(
                                  "End element chunk too short. Need at least 8 bytes. Available: "
                                  + contents.Length + " bytes");
                    }
                    var contentReader = new BinaryReader(new MemoryStream(contents));

                    long nsId   = contentReader.ReadUInt32();
                    long nameId = contentReader.ReadUInt32();
                    Name      = _stringPool.GetString(nameId);
                    Namespace =
                        (nsId == NoNamespace) ? "" : _stringPool.GetString(nsId);
                    EventType = EventEndElement;
                    _currentElementAttributes         = null;
                    _currentElementAttributesContents = null;
                    return(EventType);
                }

                case Chunk.ResXmlTypeResourceMap:
                    if (_resourceMap != null)
                    {
                        throw new FormatException("Multiple resource maps not supported");
                    }
                    _resourceMap = new ResourceMap(chunk);
                    break;
                }
            }
            return(EventType = EndOfDocument);
        }