using System;
using System.Text;
namespace Ubisoft
{
///
/// Utility class for dealing with string type.
///
public static class HtString
{
///
/// Decodes a range of bytes from a byte pointer and a counter into a string.
///
/// Byte pointer to a sequence of bytes to decode.
/// The number of bytes to decode.
/// A string containing the results of decoding the specified sequence of bytes.
public static unsafe string DecodeUtf8(byte* bytes, int count)
{
return Encoding.UTF8.GetString(bytes, count);
}
public static byte[] GetBytes(string str, bool isUtf8)
{
byte[] bytes;
if (isUtf8)
{
bytes = Encoding.UTF8.GetBytes(str);
}
else
{
bytes = new byte[str.Length * sizeof(char)];
Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
}
return bytes;
}
}
}