public unsafe static int ulongToStr(wstring s, ulong x, int digits = 1, bool bNumber = false) { if (s == null) { return(-1); } int i = 0; int num = 0; fixed(char *ptr = s.ToString()) { while (x != 0uL) { if (bNumber && num == 3) { ptr[i++] = ','; num = 0; } ptr[i++] = m_numChar[(int)(checked ((IntPtr)(x % 10uL)))]; x = (ulong)(x * 0.1); if (bNumber) { num++; } } while (i < digits) { ptr[i++] = m_numChar[0]; } wstringManager.reverse(s, i); ptr[i] = '\0'; s.Length = i; return(i); } }
public void Substring(wstring s, int startIndex) { if (s == null || startIndex <= 0 || startIndex >= s.Length) { return; } Substring(s.ToString(), startIndex, s.Length - startIndex); }
public void Append(wstring value) { if (value == null) { return; } InternalAppend(value.ToString(), value.Length); }
public void Insert(int StartIndex, wstring textS, int SLength = -1) { if (textS == null) { return; } InternalInsert(StartIndex, textS.ToString(), (SLength != -1) ? SLength : textS.Length); }
public void AppendFormat(wstring format) { wstringManager.Instance.m_formatStringCount = 0; if (format == null) { return; } InternalAppendFormat(format.ToString(), format.Length); }
public unsafe int GetHashCode(bool bToUpper = false) { int hashCode; if (bToUpper) { wstring cString = wstringManager.Instance.StaticString1024(); fixed(char *ptr = cString.ToString()) { int num = 0; while (num < m_length && num < cString.MaxLength) { if ('a' <= m_myString[num] && m_myString[num] <= 'z') { ptr[num] = (char)((int)m_myString[num] & -33); } else { ptr[num] = m_myString[num]; } num++; } ptr[num] = '\0'; cString.SetLength(num); hashCode = cString.ToString().GetHashCode(); cString.SetLength(cString.MaxLength); } } else { fixed(char *ptr2 = m_myString) { SetLength(m_length); hashCode = m_myString.GetHashCode(); SetLength(m_maxLength); } } return(hashCode); }
public unsafe static int IntToStr(wstring s, long x, int digits = 1, bool bNumber = false) { if (s == null) { return(-1); } int i = 0; int num = 0; int num2 = (x >= 0L) ? 1 : -1; if (num2 < 0) { x *= -1L; } fixed(char *ptr = s.ToString()) { while (x != 0L) { if (bNumber && num == 3) { ptr[i++] = ','; num = 0; } ptr[i++] = m_numChar[(int)(checked ((IntPtr)(x % 10L)))]; x = (long)((double)x * 0.1); if (bNumber) { num++; } } while (i < digits) { ptr[i++] = m_numChar[0]; } if (num2 < 0) { ptr[i++] = '-'; } wstringManager.reverse(s, i); ptr[i] = '\0'; s.Length = i; return(i); } }
private unsafe static void reverse(wstring s, int len) { if (s == null) { return; } int i = 0; int num = len - 1; while (i < num) { fixed(char *ptr = s.ToString()) { char c = ptr[i]; ptr[i] = ptr[num]; ptr[num] = c; i++; num--; } } }
public unsafe static void DoubleToStr(wstring s, double f, int afterpoint = -1, bool bAfterPointShowZero = true) { int num = 1; int num2 = -1; int num3 = (f >= 0.0) ? 1 : -1; if (num3 < 0) { f *= -1.0; } int num4; if (afterpoint < 0) { num4 = (int)f; double num5 = f - (double)num4; afterpoint = 0; while (num5 != 0.0 && num5 >= 0.0) { num5 = f * Math.Pow(10.0, (double)(afterpoint + 1)); num4 = (int)num5; num5 -= (double)num4; afterpoint++; } } else { double num6 = f; for (int i = 0; i < afterpoint; i++) { num6 *= 10.0; } num4 = (int)num6; } while ((f *= 0.10000000149011612) >= 1.0) { num++; } if (!bAfterPointShowZero && afterpoint > 0) { int num7 = num4; int num8 = 0; for (int j = 0; j < afterpoint; j++) { if (num7 % 10 != 0) { break; } num8++; num7 /= 10; } if (num8 > 0) { num4 /= (int)Math.Pow(10.0, (double)num8); afterpoint -= num8; } } if (afterpoint > 0) { num2 = num; num = num + 1 + afterpoint; } if (num3 < 0) { num++; if (num2 != -1) { num2++; } } fixed(char *ptr = s.ToString()) { for (int j = num; j >= 0; j--) { if (j == num) { ptr[j] = '\0'; } else if (j == num2) { ptr[j] = '.'; } else if (num3 < 0 && j == 0) { ptr[j] = '-'; } else { int num9 = num4 % 10; ptr[j] = m_numChar[num9]; num4 = (int)((float)num4 * 0.1f); } } s.Length = num; } }
void wstringTest() { using (profiler.Sample("wstring")) { using (profiler.Sample("Format")) { wstring gf = wstringManager.Instance.StaticString1024(); gf.IntToFormat(123); gf.FloatToFormat(3.148f); gf.Append("Text"); gf.AppendFormat("Number = {0}, Float = {1} String = {2}"); int x = 10; wstringManager.Instance.DeSpawnString(gf); } using (profiler.Sample("Concat")) { wstring gf = wstringManager.Instance.StaticString1024(); gf.Append("That's "); gf.Append("a lot"); gf.Append(" of"); gf.Append(" strings"); gf.Append(" to "); gf.Append("concat"); gf.AppendFormat("{0}{1}{2}{3}{4}{5}"); wstringManager.Instance.DeSpawnString(gf); int x = 10; } //功能缺失只能使用string替代 using (profiler.Sample("Substring + IndexOf + LastIndexOf")) { string path = "Path/To/Some/File.txt"; int period = path.IndexOf('.'); var ext = path.Substring(period + 1); var file = path.Substring(path.LastIndexOf('/') + 1, 4); int x = 10; } //功能缺失只能使用string替代 using (profiler.Sample("Replace (char)")) { string input = "This is some sort of text"; string replacement = input.Replace('o', '0').Replace('i', '1'); int x = 10; } //功能缺失只能使用string替代 using (profiler.Sample("Replace (string)")) { string input = "m_This is the is is form of text"; string replacement = input.Replace("m_", "").Replace("is", "si"); int x = 10; } using (profiler.Sample("Concat + Intern")) { for (int i = 0; i < 4; i++) { wstring gf = wstringManager.Instance.StaticString1024(); gf.StringToFormat("Item"); gf.IntToFormat(i); gf.AppendFormat("{0}{1}"); dict[string.Intern(gf.ToString())] = i; wstringManager.Instance.DeSpawnString(gf); } wstring gf02 = wstringManager.Instance.StaticString1024(); gf02.Append("I'm "); gf02.Append("long "); gf02.Append("gone "); gf02.Append("by "); gf02.Append("the "); gf02.Append("end "); gf02.Append("of "); gf02.Append("this "); gf02.Append("gstring block "); gf02.AppendFormat("{0}{1}{2}{3}{4}{5}{6}{7}"); outsideString1 = gf02.ToString(); wstringManager.Instance.DeSpawnString(gf02); wstring gf03 = wstringManager.Instance.StaticString1024(); gf03.Append("I'll "); gf03.Append("be "); gf03.Append("still "); gf03.Append("around "); gf03.Append("here"); gf03.Append("{0}{1}{2}{3}{4}"); outsideString = string.Intern(gf03.ToString()); wstringManager.Instance.DeSpawnString(gf03); int x = 10; } using (profiler.Sample("ToUpper + ToLower")) { wstring gf = wstringManager.Instance.StaticString1024(); gf.Append("Hello"); gf.AppendFormat("{0}"); gf.ToUpper(); wstring gf02 = wstringManager.Instance.StaticString1024(); gf02.Append(gf); gf02.Append(gf.ToString().ToLower()); gf02.AppendFormat("{0}{1}"); wstringManager.Instance.DeSpawnString(gf); wstringManager.Instance.DeSpawnString(gf02); int x = 10; } if (!bigStringTest) { return; } using (profiler.Sample("BigStringEval")) { wstring gf = wstringManager.Instance.StaticString1024(); gf.Append(bigString); gf.Append("hello"); gf.AppendFormat("{0}{1}"); } } }