PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/Mono.Cecil.Metadata/UserStringHeap.cs

http://github.com/jbevain/cecil
C# | 36 lines | 19 code | 8 blank | 9 comment | 2 complexity | 7d1ce9aa6e87ebb591599442a5b4a303 MD5 | raw file
 1//
 2// Author:
 3//   Jb Evain (jbevain@gmail.com)
 4//
 5// Copyright (c) 2008 - 2015 Jb Evain
 6// Copyright (c) 2008 - 2011 Novell, Inc.
 7//
 8// Licensed under the MIT/X11 license.
 9//
10
11namespace Mono.Cecil.Metadata {
12
13	sealed class UserStringHeap : StringHeap {
14
15		public UserStringHeap (byte [] data)
16			: base (data)
17		{
18		}
19
20		protected override string ReadStringAt (uint index)
21		{
22			int start = (int) index;
23
24			uint length = (uint) (data.ReadCompressedUInt32 (ref start) & ~1);
25			if (length < 1)
26				return string.Empty;
27
28			var chars = new char [length / 2];
29
30			for (int i = start, j = 0; i < start + length; i += 2)
31				chars [j++] = (char) (data [i] | (data [i + 1] << 8));
32
33			return new string (chars);
34		}
35	}
36}