using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Text; namespace Sog { /// /// 16 /// 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(); } } /// /// 32 /// 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(); } } /// /// 64 /// 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(); } } /// /// 128 /// 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(); } } /// /// 256 /// 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(); } } }