internal string GetString(StringHandle handle, MetadataStringDecoder utf8Decoder) { byte[] prefix; if (handle.IsVirtual) { switch (handle.StringKind) { case StringKind.Virtual: return(s_virtualValues[(int)handle.GetVirtualIndex()]); case StringKind.WinRTPrefixed: prefix = MetadataReader.WinRTPrefix; break; default: Debug.Assert(false, "We should not get here"); return(null); } } else { prefix = null; } int bytesRead; char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return(this.Block.PeekUtf8NullTerminated(handle.GetHeapOffset(), prefix, utf8Decoder, out bytesRead, otherTerminator)); }
private string GetNonVirtualString(StringHandle handle, MetadataStringDecoder utf8Decoder, byte[] prefixOpt) { Debug.Assert(handle.StringKind != StringKind.Virtual); int bytesRead; char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return(Block.PeekUtf8NullTerminated(handle.GetHeapOffset(), prefixOpt, utf8Decoder, out bytesRead, otherTerminator)); }
private unsafe MemoryBlock GetNonVirtualStringMemoryBlock(StringHandle handle) { Debug.Assert(handle.StringKind != StringKind.Virtual); int bytesRead; char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; int offset = handle.GetHeapOffset(); int length = Block.GetUtf8NullTerminatedLength(offset, out bytesRead, otherTerminator); return(new MemoryBlock(Block.Pointer + offset, length)); }
internal StringHandle GetNextHandle(StringHandle handle) { if (handle.IsVirtual) { return(default(StringHandle)); } int terminator = this.Block.IndexOf(0, handle.GetHeapOffset()); if (terminator == -1 || terminator == Block.Length - 1) { return(default(StringHandle)); } return(StringHandle.FromOffset(terminator + 1)); }
internal bool StartsWith(StringHandle handle, string value, MetadataStringDecoder utf8Decoder, bool ignoreCase) { Debug.Assert(value != null); if (handle.IsVirtual) { // TODO: This can allocate unnecessarily for <WinRT> prefixed handles. return(GetString(handle, utf8Decoder).StartsWith(value, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)); } if (handle.IsNil) { return(value.Length == 0); } char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return(this.Block.Utf8NullTerminatedStartsWith(handle.GetHeapOffset(), value, utf8Decoder, otherTerminator, ignoreCase)); }
internal bool Equals(StringHandle handle, string value, MetadataStringDecoder utf8Decoder) { Debug.Assert(value != null); if (handle.IsVirtual) { // TODO:This can allocate unnecessarily for <WinRT> prefixed handles. return(GetString(handle, utf8Decoder) == value); } if (handle.IsNil) { return(value.Length == 0); } char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return(this.Block.Utf8NullTerminatedEquals(handle.GetHeapOffset(), value, utf8Decoder, otherTerminator)); }
/// <summary> /// Equivalent to Array.BinarySearch, searches for given raw (non-virtual) handle in given array of ASCII strings. /// </summary> internal int BinarySearchRaw(string[] asciiKeys, StringHandle rawHandle) { Debug.Assert(!rawHandle.IsVirtual); Debug.Assert(rawHandle.StringKind != StringKind.DotTerminated, "Not supported"); return this.Block.BinarySearch(asciiKeys, rawHandle.GetHeapOffset()); }
private unsafe MemoryBlock GetNonVirtualStringMemoryBlock(StringHandle handle) { Debug.Assert(handle.StringKind != StringKind.Virtual); int bytesRead; char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; int offset = handle.GetHeapOffset(); int length = Block.GetUtf8NullTerminatedLength(offset, out bytesRead, otherTerminator); return new MemoryBlock(Block.Pointer + offset, length); }
internal string GetString(StringHandle handle, MetadataStringDecoder utf8Decoder) { byte[] prefix; if (handle.IsVirtual) { switch (handle.StringKind) { case StringKind.Virtual: return s_virtualValues[(int)handle.GetVirtualIndex()]; case StringKind.WinRTPrefixed: prefix = MetadataReader.WinRTPrefix; break; default: Debug.Assert(false, "We should not get here"); return null; } } else { prefix = null; } int bytesRead; char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return this.Block.PeekUtf8NullTerminated(handle.GetHeapOffset(), prefix, utf8Decoder, out bytesRead, otherTerminator); }
internal StringHandle GetNextHandle(StringHandle handle) { if (handle.IsVirtual) { return default(StringHandle); } int terminator = this.Block.IndexOf(0, handle.GetHeapOffset()); if (terminator == -1 || terminator == Block.Length - 1) { return default(StringHandle); } return StringHandle.FromOffset(terminator + 1); }
/// <summary> /// Returns the offset of metadata heap data that corresponds /// to the specified <paramref name="handle"/>. /// </summary> /// <returns> /// Zero based offset, or -1 if <paramref name="handle"/> can only be interpreted in a context of a specific <see cref="MetadataReader"/> or <see cref="MetadataBuilder"/>. /// See <see cref="GetHeapOffset(MetadataReader, Handle)"/>. /// </returns> internal static int GetHeapOffset(StringHandle handle) => handle.IsVirtual ? -1 : handle.GetHeapOffset();
private string GetNonVirtualString(StringHandle handle, MetadataStringDecoder utf8Decoder, byte[] prefixOpt) { Debug.Assert(handle.StringKind != StringKind.Virtual); int bytesRead; char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return Block.PeekUtf8NullTerminated(handle.GetHeapOffset(), prefixOpt, utf8Decoder, out bytesRead, otherTerminator); }
/// <summary> /// Equivalent to Array.BinarySearch, searches for given raw (non-virtual) handle in given array of ASCII strings. /// </summary> internal int BinarySearchRaw(string[] asciiKeys, StringHandle rawHandle) { Debug.Assert(!rawHandle.IsVirtual); Debug.Assert(rawHandle.StringKind != StringKind.DotTerminated, "Not supported"); return(this.Block.BinarySearch(asciiKeys, rawHandle.GetHeapOffset())); }
/// <summary> /// Returns true if the given raw (non-virtual) handle represents the same string as given ASCII string. /// </summary> internal bool EqualsRaw(StringHandle rawHandle, string asciiString) { Debug.Assert(!rawHandle.IsVirtual); Debug.Assert(rawHandle.StringKind != StringKind.DotTerminated, "Not supported"); return(this.Block.CompareUtf8NullTerminatedStringWithAsciiString(rawHandle.GetHeapOffset(), asciiString) == 0); }
/// <summary> /// Returns true if the given raw (non-virtual) handle represents a string that starts with given ASCII prefix. /// </summary> internal bool StartsWithRaw(StringHandle rawHandle, string asciiPrefix) { Debug.Assert(!rawHandle.IsVirtual); Debug.Assert(rawHandle.StringKind != StringKind.DotTerminated, "Not supported"); return this.Block.Utf8NullTerminatedStringStartsWithAsciiPrefix(rawHandle.GetHeapOffset(), asciiPrefix); }
/// <summary> /// Returns true if the given raw (non-virtual) handle represents the same string as given ASCII string. /// </summary> internal bool EqualsRaw(StringHandle rawHandle, string asciiString) { Debug.Assert(!rawHandle.IsVirtual); Debug.Assert(rawHandle.StringKind != StringKind.DotTerminated, "Not supported"); return this.Block.CompareUtf8NullTerminatedStringWithAsciiString(rawHandle.GetHeapOffset(), asciiString) == 0; }
internal bool StartsWith(StringHandle handle, string value, MetadataStringDecoder utf8Decoder, bool ignoreCase) { Debug.Assert(value != null); if (handle.IsVirtual) { // TODO: This can allocate unnecessarily for <WinRT> prefixed handles. return GetString(handle, utf8Decoder).StartsWith(value, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal); } if (handle.IsNil) { return value.Length == 0; } char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return this.Block.Utf8NullTerminatedStartsWith(handle.GetHeapOffset(), value, utf8Decoder, otherTerminator, ignoreCase); }
/// <summary> /// Returns true if the given raw (non-virtual) handle represents a string that starts with given ASCII prefix. /// </summary> internal bool StartsWithRaw(StringHandle rawHandle, string asciiPrefix) { Debug.Assert(!rawHandle.IsVirtual); Debug.Assert(rawHandle.StringKind != StringKind.DotTerminated, "Not supported"); return(this.Block.Utf8NullTerminatedStringStartsWithAsciiPrefix(rawHandle.GetHeapOffset(), asciiPrefix)); }
/// <summary> /// Creates a NamespaceDataBuilder instance that contains a synthesized NamespaceDefinitionHandle, /// as well as the name provided. /// </summary> private NamespaceDataBuilder SynthesizeNamespaceData(string fullName, NamespaceDefinitionHandle realChild) { Debug.Assert(realChild.HasFullName); int numberOfSegments = 0; foreach (char c in fullName) { if (c == '.') { numberOfSegments++; } } StringHandle simpleName = GetSimpleName(realChild, numberOfSegments); var namespaceHandle = NamespaceDefinitionHandle.FromSimpleNameOffset(simpleName.GetHeapOffset()); return(new NamespaceDataBuilder(namespaceHandle, simpleName, fullName)); }
/// <summary> /// Returns the offset of metadata heap data that corresponds /// to the specified <paramref name="handle"/>. /// </summary> /// <returns> /// Zero based offset, or -1 if <paramref name="handle"/> can only be interpreted in a context of a specific <see cref="MetadataReader"/> or <see cref="MetadataBuilder"/>. /// See <see cref="GetHeapOffset(MetadataReader, Handle)"/>. /// </returns> public static int GetHeapOffset(StringHandle handle) => handle.IsVirtual ? -1 : handle.GetHeapOffset();
internal bool Equals(StringHandle handle, string value, MetadataStringDecoder utf8Decoder) { Debug.Assert(value != null); if (handle.IsVirtual) { // TODO:This can allocate unnecessarily for <WinRT> prefixed handles. return GetString(handle, utf8Decoder) == value; } if (handle.IsNil) { return value.Length == 0; } char otherTerminator = handle.StringKind == StringKind.DotTerminated ? '.' : '\0'; return this.Block.Utf8NullTerminatedEquals(handle.GetHeapOffset(), value, utf8Decoder, otherTerminator); }