コード例 #1
0
ファイル: StringPool.cs プロジェクト: yuva2achieve/dot42
        /// <summary>
        /// Encode a string data array.
        /// </summary>
        private static void BuildStringsData(List <Entry> list, bool isUtf8, ResWriter writer, out int[] offsets, out byte[] data)
        {
            // Build offsets
            offsets = new int[list.Count];

            // Build data
            var dataStream = new MemoryStream();
            var dataWriter = new ResWriter(dataStream, writer.BigEndian);

            for (var i = 0; i < list.Count; i++)
            {
                var s = list[i].Value;
                offsets[i] = (int)dataStream.Position;
                if (isUtf8)
                {
                    EncodeLength8(dataWriter, s.Length); // u16 length
                    var encoded = AndroidEncodings.UTF8.GetBytes(s);
                    EncodeLength8(dataWriter, encoded.Length);
                    dataStream.Write(encoded, 0, encoded.Length);
                }
                else
                {
                    EncodeLength16(dataWriter, s.Length);
                    foreach (var ch in s)
                    {
                        dataWriter.WriteUInt16(ch);
                    }
                    dataWriter.WriteUInt16(0); // Pad with '\0'
                }
            }

            // Pad with '0' to end on 4 byte boundary
            dataWriter.PadAlign(4);

            // Return actual data
            data = dataStream.ToArray();
        }