mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
Added String.IndexOf(string)
Added String.Insert(int, string) Added String.Replace(string, string)
This commit is contained in:
parent
768d83e799
commit
697bbbdf06
3 changed files with 31 additions and 52 deletions
|
|
@ -141,6 +141,12 @@ namespace Cosmos.Kernel.Plugs {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int IndexOf(string aThis,
|
||||||
|
string aValue)
|
||||||
|
{
|
||||||
|
return aThis.IndexOf(aValue, 0, aThis.Length, StringComparison.CurrentCulture);
|
||||||
|
}
|
||||||
|
|
||||||
public static int IndexOf(string aThis,
|
public static int IndexOf(string aThis,
|
||||||
char aSeparator,
|
char aSeparator,
|
||||||
int aStartIndex,
|
int aStartIndex,
|
||||||
|
|
@ -170,6 +176,11 @@ namespace Cosmos.Kernel.Plugs {
|
||||||
return xResult;
|
return xResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string Insert(string aThis, int aStartPos, string aValue)
|
||||||
|
{
|
||||||
|
return aThis.Substring(0, aStartPos) + aValue + aThis.Substring(aStartPos);
|
||||||
|
}
|
||||||
|
|
||||||
public static int LastIndexOf(string aThis, char aChar, int aStartIndex, int aCount)
|
public static int LastIndexOf(string aThis, char aChar, int aStartIndex, int aCount)
|
||||||
{
|
{
|
||||||
return LastIndexOfAny(aThis, new char[] {aChar}, aStartIndex, aCount);
|
return LastIndexOfAny(aThis, new char[] {aChar}, aStartIndex, aCount);
|
||||||
|
|
@ -212,44 +223,15 @@ namespace Cosmos.Kernel.Plugs {
|
||||||
return aThis.Substring(0, aStart) + aThis.Substring(aStart+aCount, aThis.Length-(aStart+aCount));
|
return aThis.Substring(0, aStart) + aThis.Substring(aStart+aCount, aThis.Length-(aStart+aCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
//private static string[] Split(string aThis,
|
public static string Replace(string aThis, string oldValue, string newValue)
|
||||||
// char[] aSeparators,
|
{
|
||||||
// StringSplitOptions aSplitOptions)
|
while (aThis.IndexOf(oldValue) != -1)
|
||||||
//{
|
{
|
||||||
// List<string> xResult = new List<string>();
|
int xIndex = aThis.IndexOf(oldValue);
|
||||||
// int xCurPos = 0;
|
aThis = aThis.Remove(xIndex, oldValue.Length);
|
||||||
// if (CharArrayContainsChar(aSeparators,
|
aThis = aThis.Insert(xIndex, newValue);
|
||||||
// aThis[0]))
|
}
|
||||||
// {
|
return aThis;
|
||||||
// xCurPos = 1;
|
}
|
||||||
// if (aSplitOptions == StringSplitOptions.None)
|
|
||||||
// {
|
|
||||||
// xResult.Add("");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// while (xCurPos < aThis.Length)
|
|
||||||
// {
|
|
||||||
// int xNextPos = String.IndexOfAny(aThis,
|
|
||||||
// aSeparators,
|
|
||||||
// xCurPos, aThis.Length - xCurPos);
|
|
||||||
// if (xNextPos == -1)
|
|
||||||
// {
|
|
||||||
// xResult.Add(aThis.Substring(xCurPos));
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// if (xNextPos == xCurPos)
|
|
||||||
// {
|
|
||||||
// if (aSplitOptions == StringSplitOptions.None)
|
|
||||||
// {
|
|
||||||
// xResult.Add("");
|
|
||||||
// }
|
|
||||||
// xCurPos = xNextPos + 1;
|
|
||||||
// }
|
|
||||||
// xResult.Add(aThis.Substring(xCurPos,
|
|
||||||
// xNextPos - xCurPos));
|
|
||||||
// xCurPos = xNextPos + 1;
|
|
||||||
// }
|
|
||||||
// return xResult.ToArray();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -71,13 +71,15 @@ namespace FrodeTest.Test
|
||||||
Check.Text = "String.IndexOf";
|
Check.Text = "String.IndexOf";
|
||||||
Check.Validate("test".IndexOf('t', 0, 2) == 0);
|
Check.Validate("test".IndexOf('t', 0, 2) == 0);
|
||||||
Check.Validate("test".IndexOf('B', 1, 1) == -1);
|
Check.Validate("test".IndexOf('B', 1, 1) == -1);
|
||||||
|
Check.Validate("test".IndexOf("st") == 2);
|
||||||
|
Check.Validate("test".IndexOf("es", 1, 3, StringComparison.CurrentCulture) == 1);
|
||||||
|
|
||||||
Check.Text = "String.IndexOfAny";
|
Check.Text = "String.IndexOfAny";
|
||||||
Check.Validate("test".IndexOfAny(new char[] { 'a', 'b' }, 0, 4) == -1);
|
Check.Validate("test".IndexOfAny(new char[] { 'a', 'b' }, 0, 4) == -1);
|
||||||
Check.Validate("test".IndexOfAny(new char[] { 'e', 's' }, 0, 4) == 1);
|
Check.Validate("test".IndexOfAny(new char[] { 'e', 's' }, 0, 4) == 1);
|
||||||
|
|
||||||
//Check.Text = "String.Insert";
|
Check.Text = "String.Insert";
|
||||||
//Check.Validate("Hello".Insert(5, " World").Equals("Hello World"));
|
Check.Validate("Hello".Insert(5, " World").Equals("Hello World"));
|
||||||
|
|
||||||
//Check.Text = "String.IsNormalized";
|
//Check.Text = "String.IsNormalized";
|
||||||
//Check.Validate("test".IsNormalized());
|
//Check.Validate("test".IsNormalized());
|
||||||
|
|
@ -85,6 +87,9 @@ namespace FrodeTest.Test
|
||||||
Check.Text = "String.LastIndexOf";
|
Check.Text = "String.LastIndexOf";
|
||||||
Check.Validate("Readme.txt".LastIndexOf('.') == 6);
|
Check.Validate("Readme.txt".LastIndexOf('.') == 6);
|
||||||
|
|
||||||
|
Console.WriteLine("Press any key to continue");
|
||||||
|
Console.ReadLine();
|
||||||
|
|
||||||
Check.Text = "String.LastIndexOfAny";
|
Check.Text = "String.LastIndexOfAny";
|
||||||
Check.Validate("test".LastIndexOfAny(new char[] { 'a', 'b' }, 0, 4) == -1);
|
Check.Validate("test".LastIndexOfAny(new char[] { 'a', 'b' }, 0, 4) == -1);
|
||||||
Check.Validate("test".LastIndexOfAny(new char[] { 'a', 't' }, 3, 4) == 3);
|
Check.Validate("test".LastIndexOfAny(new char[] { 'a', 't' }, 3, 4) == 3);
|
||||||
|
|
@ -105,10 +110,11 @@ namespace FrodeTest.Test
|
||||||
Check.Validate("test".Remove(2).Equals("te"));
|
Check.Validate("test".Remove(2).Equals("te"));
|
||||||
Check.Validate("test".Remove(1, 2).Equals("tt"));
|
Check.Validate("test".Remove(1, 2).Equals("tt"));
|
||||||
|
|
||||||
|
|
||||||
Check.Text = "String.Replace(char, char)";
|
Check.Text = "String.Replace(char, char)";
|
||||||
Check.Validate("test".Replace('t', 'p').Equals("pesp"));
|
Check.Validate("test".Replace('t', 'p').Equals("pesp"));
|
||||||
Check.Text = "String.Replace(string, string)";
|
Check.Text = "String.Replace(string, string)";
|
||||||
//Check.Validate("test".Replace("es", "amti").Equals("tamtit")); //Uses .Insert - fix that first.
|
Check.Validate("test".Replace("es", "amti").Equals("tamtit")); //Uses .Insert - fix that first.
|
||||||
|
|
||||||
Check.Text = "String.Split";
|
Check.Text = "String.Split";
|
||||||
Check.Validate("Hello World".Split(new string[] { "l" }, 30, StringSplitOptions.RemoveEmptyEntries).Length == 3);
|
Check.Validate("Hello World".Split(new string[] { "l" }, 30, StringSplitOptions.RemoveEmptyEntries).Length == 3);
|
||||||
|
|
|
||||||
|
|
@ -96,16 +96,7 @@ namespace Indy.IL2CPU.CustomImplementation.System {
|
||||||
return new string(cs);
|
return new string(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Replace(string aThis, string oldValue, string newValue)
|
|
||||||
{
|
|
||||||
while (aThis.IndexOf(oldValue) != -1)
|
|
||||||
{
|
|
||||||
int xIndex = aThis.IndexOf(oldValue);
|
|
||||||
aThis.Remove(xIndex, oldValue.Length);
|
|
||||||
aThis.Insert(xIndex, newValue);
|
|
||||||
}
|
|
||||||
return aThis;
|
|
||||||
}
|
|
||||||
|
|
||||||
// HACK: We need to redo this once char support is complete (only returns 0, -1).
|
// HACK: We need to redo this once char support is complete (only returns 0, -1).
|
||||||
public static int CompareTo(string aThis, string other) {
|
public static int CompareTo(string aThis, string other) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue