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)]

View File

@@ -8231,12 +8231,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_String llSHA256String(LSL_String input)
{
byte[] bytes;
// Create a SHA256
using SHA256 sha256Hash = SHA256.Create();
// ComputeHash - returns byte array
Span<byte> bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)).AsSpan();
return Util.bytesToHexString(bytes, true);
using (SHA256 sha256Hash = SHA256.Create())
{
// ComputeHash - returns byte array
bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input.m_string));
}
return Util.bytesToLowcaseHexString(bytes);
}
protected ObjectShapePacket.ObjectDataBlock SetPrimitiveBlockShapeParams(SceneObjectPart part, int holeshape, LSL_Vector cut, float hollow, LSL_Vector twist, byte profileshape, byte pathcurve)

View File

@@ -2619,13 +2619,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public string osSHA256(string input)
{
byte[] bytes;
// Create a SHA256
using (SHA256 sha256Hash = SHA256.Create())
{
using (SHA256 sha256Hash = SHA256.Create())
{
// ComputeHash - returns byte array
Span<byte> bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)).AsSpan();
return Util.bytesToHexString(bytes, true);
bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
}
return Util.bytesToLowcaseHexString(bytes);
}
/// <summary>