diff --git a/source/Cosmos.Core.Plugs/System/StringImpl.cs b/source/Cosmos.Core.Plugs/System/StringImpl.cs index e09081023..2f9aba3a1 100644 --- a/source/Cosmos.Core.Plugs/System/StringImpl.cs +++ b/source/Cosmos.Core.Plugs/System/StringImpl.cs @@ -1,9 +1,9 @@ using System; using System.Globalization; -using Cosmos.Common; -using Cosmos.Debug.Kernel; -using Cosmos.IL2CPU.Plugs; + using Cosmos.Common; + using Cosmos.Debug.Kernel; + using Cosmos.IL2CPU.Plugs; namespace Cosmos.Core.Plugs.System { @@ -212,9 +212,9 @@ namespace Cosmos.Core.Plugs.System else if (xCharArray[i] == '{') { mDebugger.SendInternal("Found opening placeholder"); - xFoundPlaceholder = true; - xParamNumberDone = false; - xParamNumber = string.Empty; + xFoundPlaceholder = true; + xParamNumberDone = false; + xParamNumber = string.Empty; } else { @@ -227,7 +227,82 @@ namespace Cosmos.Core.Plugs.System public static bool StartsWith(string aThis, string aSubstring, StringComparison aComparison) { - throw new NotImplementedException(); + Char[] di = aThis.ToCharArray(); + Char[] ci = aSubstring.ToCharArray(); + if (aSubstring.Length > aThis.Length) + { + return false; + } + for (int i = 0; i < ci.Length; i++) + { + if (di[i] != ci[i]) + { + return false; + + } + } + return true; + } + + //String concatenation plugs + public static string Concat(string str0) + { + return str0; + } + + public static string Concat(string str0, string str1) + { + return Concat(new[] { str0, str1 }); + } + + public static string Concat(string str0, string str1, string str2) + { + return Concat(new[] { str0, str1, str2 }); + } + + public static string Concat(string str0, string str1, string str2, string str3) + { + return Concat(new[] { str0, str1, str2, str3 }); + } + + //Object concatenation plugs + public static string Concat(object obj0) + { + return obj0?.ToString(); + } + + public static string Concat(object obj0, object obj1) + { + return Concat(obj0?.ToString(), obj1?.ToString()); + } + + public static string Concat(object obj0, object obj1, object obj2) + { + return Concat(obj0?.ToString(), obj1?.ToString(), obj2?.ToString()); + } + + public static string Concat(object obj0, object obj1, object obj2, object obj3) + { + return Concat(new[] { obj0?.ToString(), obj1?.ToString(), obj2?.ToString(), obj3?.ToString() }); + } + + //Array concatenation plugs + public static string Concat(params string[] values) + { + if (values != null) + { + int len = 0; + for (int i = 0; i < values.Length; i++) + { + string xValue = values[i]; + if (xValue != null) + { + len += values[i].Length; + } + } + return ConcatArray(values, len); + } + return string.Empty; } public static string PadHelper(string aThis, int totalWidth, char paddingChar, bool isRightPadded) @@ -463,11 +538,36 @@ namespace Cosmos.Core.Plugs.System public static bool Contains(string aThis, string value) { - if (aThis.IndexOf(value) != -1) + Char[] di = aThis.ToCharArray(); + Char[] ci = value.ToCharArray(); + if (value.Length == aThis.Length) { + if (value == aThis) + { return true; } - + else + { + return false; + } + } + else if (!(value.Length > aThis.Length) && (value.Length != aThis.Length)) + { + for (int i = 0; i < aThis.Length; i++) + { + if (di[i] == ci[0]) + { + for (int j = 1; j < value.Length; j++) + { + if (di[i + j] != ci[j]) + { + return false; + } + } + return true; + } + } + } return false; } @@ -478,31 +578,32 @@ namespace Cosmos.Core.Plugs.System public static bool EndsWith(string aThis, string aSubStr, StringComparison aComparison) { - if (aSubStr == null) + Char[] di = aThis.ToCharArray(); + Char[] ci = aSubStr.ToCharArray(); + if (aThis.Length == aSubStr.Length) { - throw new ArgumentNullException("aSubStr"); - } - if (aThis == aSubStr) { return true; } - - if (aSubStr.Length == 0) - { - return true; + return false; } - - int xLastIdx = aThis.Length - aSubStr.Length; - for (int i = 0; i < aSubStr.Length; i++) + else if (aThis.Length > aSubStr.Length) { - if (aThis[xLastIdx + i] != aSubStr[i]) + return false; + } + else + { + for (int i = aThis.Length - aSubStr.Length; i < aThis.Length; i++) + { + if (di[aThis.Length - aSubStr.Length + i] != ci[i]) { return false; } } return true; } + } // System.Int32 System.String.IndexOf(System.String, System.Int32, System.Int32, System.StringComparison) @@ -603,15 +704,15 @@ namespace Cosmos.Core.Plugs.System { mDebugger.SendInternal("nativeCompareOrdinalEx : aStrA is null"); if (aStrB == null) - { + { mDebugger.SendInternal($"nativeCompareOrdinalEx : aStrB is null"); mDebugger.SendInternal($"nativeCompareOrdinalEx : returning 0"); - return 0; - } + return 0; + } mDebugger.SendInternal($"nativeCompareOrdinalEx : aStrB is not null"); mDebugger.SendInternal($"nativeCompareOrdinalEx : returning -1"); - return -1; - } + return -1; + } if (aStrB == null) { mDebugger.SendInternal("nativeCompareOrdinalEx : aStrA is not null"); @@ -651,11 +752,18 @@ namespace Cosmos.Core.Plugs.System public static bool StartsWith(string aThis, string aSubStr, bool aIgnoreCase, CultureInfo aCulture) { - for (int i = 0; i < aSubStr.Length; i++) + Char[] di = aThis.ToCharArray(); + Char[] ci = aSubStr.ToCharArray(); + if (aSubStr.Length > aThis.Length) { - if (aThis[i] != aSubStr[i]) + return false; + } + for (int i = 0; i < ci.Length; i++) + { + if (di[i] != ci[i]) { return false; + } } return true; @@ -721,5 +829,29 @@ namespace Cosmos.Core.Plugs.System { return new string(new char[length]); } + + public static string TrimStart(string aThis, string aSubStr) + { + char[] ci = aThis.ToCharArray(); + char[] di = aSubStr.ToCharArray(); + + if(aThis.StartsWith(aSubStr)) + { + if(aThis != aSubStr) + { + char[] oi = new char[ci.Length - di.Length]; + for(int i=0; i < ci.Length - di.Length; i++) + { + oi[i] = ci[i + di.Length]; + } + return oi.ToString(); + } + + return string.Empty; + } + + throw new ArgumentNullException(); + } + } -} +} \ No newline at end of file