cosmetics

This commit is contained in:
UbitUmarov
2022-10-22 22:51:55 +01:00
parent 5a7157efc8
commit d27516ac01
4 changed files with 68 additions and 31 deletions

View File

@@ -324,10 +324,8 @@ namespace OpenSim.Framework.Console
m_cursorYPosition = SetCursorZeroLeft(m_cursorYPosition);
int count = m_commandLine.Length + prompt.Length;
char[] spaces = new char[count];
for(int i = 0; i < spaces.Length; i++)
spaces[i] = ' ';
System.Console.Write(spaces);
if(count > 0)
System.Console.Write(new string(' ', count));
m_cursorYPosition = SetCursorZeroLeft(m_cursorYPosition);
}
@@ -444,11 +442,12 @@ namespace OpenSim.Framework.Console
m_cursorYPosition = SetCursorZeroLeft(m_cursorYPosition);
int count = m_commandLine.Length + prompt.Length - text.Length;
WriteLocalText(text, level);
for (int i = 0; i < count; ++i)
System.Console.Write(" ");
System.Console.WriteLine();
if(count > 0)
System.Console.WriteLine(new string(' ', count));
else
System.Console.WriteLine();
m_cursorYPosition = System.Console.CursorTop;
Show();
}

View File

@@ -1230,31 +1230,66 @@ namespace OpenSim.Framework
return (char)(b > 9 ? b + 0x37 : b + '0');
}
public static string bytesToHexString(Span<byte> bytes, bool lowerCaps)
public static unsafe string bytesToHexString(byte[] bytes, bool lowerCaps)
{
if (bytes == null || bytes.Length == 0)
return string.Empty;
Span<char> chars = stackalloc char[2 * bytes.Length];
if (lowerCaps)
return string.Create(2 * bytes.Length, bytes, (chars, bytes) =>
{
fixed (char* dstb = chars)
fixed (byte* srcb = bytes)
{
char* dst = dstb;
if (lowerCaps)
{
for (int i = 0; i < bytes.Length; ++i)
{
byte b = srcb[i];
*dst++ = HighNibbleToHexByteCharLowcaps(b);
*dst++ = LowNibbleToHexByteCharLowcaps(b);
}
}
else
{
for (int i = 0; i < bytes.Length; ++i)
{
byte b = srcb[i];
*dst++ = HighNibbleToHexByteCharLowcaps(b);
*dst++ = LowNibbleToHexByteCharLowcaps(b);
}
}
}
});
}
public static unsafe string bytesToLowcaseHexString(byte[] bytes)
{
if (bytes == null || bytes.Length == 0)
return string.Empty;
return string.Create(2 * bytes.Length, bytes, (chars, bytes) =>
{
fixed (char* dstb = chars)
fixed (byte* srcb = bytes)
{
char* dst = dstb;
for (int i = 0; i < bytes.Length; ++i)
{
byte b = srcb[i];
*dst++ = HighNibbleToHexByteCharLowcaps(b);
*dst++ = LowNibbleToHexByteCharLowcaps(b);
}
}
/*
for (int i = 0, j = 0; i < bytes.Length; ++i)
{
byte b = bytes[i];
chars[j++] = HighNibbleToHexByteCharLowcaps(b);
chars[j++] = LowNibbleToHexByteCharLowcaps(b);
}
}
else
{
for (int i = 0, j = 0; i < bytes.Length; ++i)
{
byte b = bytes[i];
chars[j++] = HighNibbleToHexByteCharHighcaps(b);
chars[j++] = LowNibbleToHexByteCharHighcaps(b);
}
}
return new string(chars);
*/
});
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]