public unsafe void TestWellKnownStrings(string input, bool expected) { // create a copy of the data; no cheating! byte[] bytes = Encoding.ASCII.GetBytes(input); fixed(byte *ptr = bytes) { string result = WellKnownStrings.TryIdentify(ptr, bytes.Length); if (expected) { Assert.AreEqual(input, result); } else { Assert.IsNull(result); } if (expected) { // try again, and check we get the same instance string again = WellKnownStrings.TryIdentify(ptr, bytes.Length); Assert.AreSame(result, again); } } }
/// <summary>Gets a string from the strings section by the string's well-known index.</summary> /// <param name="stringTableIndex">The index of the string to find.</param> /// <returns>The string if it's in the database; otherwise, null.</returns> public string GetString(WellKnownStrings stringTableIndex) { int index = (int)stringTableIndex; Debug.Assert(index >= 0); if (index >= _stringSectionNumOffsets) { // Some terminfo files may not contain enough entries to actually // have the requested one. return(null); } int tableIndex = ReadInt16(_data, StringOffsetsOffset + (index * 2)); if (tableIndex == -1) { // Some terminfo files may have enough entries, but may not actually // have it filled in for this particular string. return(null); } return(ReadString(_data, StringsTableOffset + tableIndex)); }
/// <summary>Gets a string from the strings section by the string's well-known index.</summary> /// <param name="stringTableIndex">The index of the string to find.</param> /// <returns>The string if it's in the database; otherwise, null.</returns> public string GetString(WellKnownStrings stringTableIndex) { int index = (int)stringTableIndex; Debug.Assert(index >= 0); if (index >= _stringSectionNumOffsets) { // Some terminfo files may not contain enough entries to actually // have the requested one. return null; } int tableIndex = ReadInt16(_data, StringOffsetsOffset + (index * 2)); if (tableIndex == -1) { // Some terminfo files may have enough entries, but may not actually // have it filled in for this particular string. return null; } return ReadString(_data, StringsTableOffset + tableIndex); }