You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
405 lines
8.6 KiB
405 lines
8.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Text;
|
|
|
|
namespace Sog
|
|
{
|
|
/// <summary>
|
|
/// 16
|
|
/// </summary>
|
|
unsafe public struct StructString16
|
|
{
|
|
const int BuffSize = 16;
|
|
|
|
public fixed char m_buff[BuffSize];
|
|
|
|
public int Length()
|
|
{
|
|
int length = 0;
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if(p[i] != '\0')
|
|
{
|
|
length++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return length;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
fixed(char* p = m_buff)
|
|
{
|
|
for(int i=0; i< BuffSize; i++)
|
|
{
|
|
p[i] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CopyFromString(string value)
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
p[0] = '\0';
|
|
|
|
if(string.IsNullOrEmpty(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
for(int i=0; i< value.Length && i< BuffSize; i++)
|
|
{
|
|
p[i] = value[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
sb.Append(p[i]);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 32
|
|
/// </summary>
|
|
unsafe public struct StructString32
|
|
{
|
|
const int BuffSize = 32;
|
|
|
|
public fixed char m_buff[BuffSize];
|
|
|
|
public int Length()
|
|
{
|
|
int length = 0;
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
length++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return length;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
p[i] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CopyFromString(string value)
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
p[0] = '\0';
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < value.Length && i < BuffSize; i++)
|
|
{
|
|
p[i] = value[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
sb.Append(p[i]);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 64
|
|
/// </summary>
|
|
unsafe public struct StructString64
|
|
{
|
|
const int BuffSize = 64;
|
|
|
|
public fixed char m_buff[BuffSize];
|
|
|
|
public int Length()
|
|
{
|
|
int length = 0;
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
length++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return length;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
p[i] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CopyFromString(string value)
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
p[0] = '\0';
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < value.Length && i < BuffSize; i++)
|
|
{
|
|
p[i] = value[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
sb.Append(p[i]);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 128
|
|
/// </summary>
|
|
unsafe public struct StructString128
|
|
{
|
|
const int BuffSize = 128;
|
|
|
|
public fixed char m_buff[BuffSize];
|
|
|
|
public int Length()
|
|
{
|
|
int length = 0;
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
length++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return length;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
p[i] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CopyFromString(string value)
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
p[0] = '\0';
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < value.Length && i < BuffSize; i++)
|
|
{
|
|
p[i] = value[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
sb.Append(p[i]);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 256
|
|
/// </summary>
|
|
unsafe public struct StructString256
|
|
{
|
|
const int BuffSize = 256;
|
|
|
|
public fixed char m_buff[BuffSize];
|
|
|
|
public int Length()
|
|
{
|
|
int length = 0;
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
length++;
|
|
}
|
|
}
|
|
}
|
|
|
|
return length;
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
p[i] = '\0';
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CopyFromString(string value)
|
|
{
|
|
fixed (char* p = m_buff)
|
|
{
|
|
p[0] = '\0';
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
{
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < value.Length && i < BuffSize; i++)
|
|
{
|
|
p[i] = value[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
fixed (char* p = m_buff)
|
|
{
|
|
for (int i = 0; i < BuffSize; i++)
|
|
{
|
|
if (p[i] != '\0')
|
|
{
|
|
sb.Append(p[i]);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|
|
|