Added CPL license header to files where it was amiss; added StringHelper class with IndexNotOfAny() and LastIndexNotOfAny() (inverted variants of the IndexOfAny() methods in the .NET framework)
git-svn-id: file:///srv/devel/repo-conversion/nusu@84 d2e56fa2-650e-0410-a79f-9358c0239efd
This commit is contained in:
parent
221a40e57f
commit
df948d2eab
|
@ -177,6 +177,8 @@
|
||||||
<Compile Include="Source\SpatialPartitioning\RTreeLeaf2.cs" />
|
<Compile Include="Source\SpatialPartitioning\RTreeLeaf2.cs" />
|
||||||
<Compile Include="Source\SpatialPartitioning\RTreeNode2.cs" />
|
<Compile Include="Source\SpatialPartitioning\RTreeNode2.cs" />
|
||||||
<Compile Include="Source\SpatialPartitioning\SpatialIndex2.cs" />
|
<Compile Include="Source\SpatialPartitioning\SpatialIndex2.cs" />
|
||||||
|
<Compile Include="Source\StringHelper.cs" />
|
||||||
|
<Compile Include="Source\StringHelper.Test.cs" />
|
||||||
<Compile Include="Source\Tracking\IdleStateEventArgs.cs" />
|
<Compile Include="Source\Tracking\IdleStateEventArgs.cs" />
|
||||||
<Compile Include="Source\Tracking\Internal\ObservedWeightedWaitable.cs" />
|
<Compile Include="Source\Tracking\Internal\ObservedWeightedWaitable.cs" />
|
||||||
<Compile Include="Source\Tracking\Internal\WeightedWaitableWrapperCollection.cs" />
|
<Compile Include="Source\Tracking\Internal\WeightedWaitableWrapperCollection.cs" />
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
using System;
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
#if UNITTEST
|
#if UNITTEST
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
using System;
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
using System;
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
|
@ -1,4 +1,24 @@
|
||||||
using System;
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Nuclex.Support {
|
namespace Nuclex.Support {
|
||||||
|
|
|
@ -1,3 +1,23 @@
|
||||||
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
40
Source/StringHelper.Test.cs
Normal file
40
Source/StringHelper.Test.cs
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
#if UNITTEST
|
||||||
|
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NUnit.Framework.SyntaxHelpers;
|
||||||
|
|
||||||
|
namespace Nuclex.Support {
|
||||||
|
|
||||||
|
/// <summary>Unit Test for the string helper class</summary>
|
||||||
|
[TestFixture]
|
||||||
|
public class PathHelperTest {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Nuclex.Support
|
||||||
|
|
||||||
|
#endif // UNITTEST
|
169
Source/StringHelper.cs
Normal file
169
Source/StringHelper.cs
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
#region CPL License
|
||||||
|
/*
|
||||||
|
Nuclex Framework
|
||||||
|
Copyright (C) 2002-2008 Nuclex Development Labs
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the IBM Common Public License as
|
||||||
|
published by the IBM Corporation; either version 1.0 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
IBM Common Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the IBM Common Public
|
||||||
|
License along with this library
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Nuclex.Support {
|
||||||
|
|
||||||
|
/// <summary>Helper routines for working with strings</summary>
|
||||||
|
public static class StringHelper {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches for the first occurence of a character other than the characters
|
||||||
|
/// listed in the <see paramref="anyNotOf" /> parameter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="haystack">String that will be scanned in</param>
|
||||||
|
/// <param name="anyNotOf">Characters to not look for in the scanned string</param>
|
||||||
|
/// <returns>
|
||||||
|
/// The index of the first occurence of a character not in the
|
||||||
|
/// <see paramref="anyNotOf" /> array or -1 if all characters in the string were
|
||||||
|
/// present in the <see paramref="anyNotOf" /> array.
|
||||||
|
/// </returns>
|
||||||
|
public static int IndexNotOfAny(string haystack, char[] anyNotOf) {
|
||||||
|
return IndexNotOfAny(haystack, anyNotOf, 0, haystack.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches for the first occurence of a character other than the characters
|
||||||
|
/// listed in the <see paramref="anyNotOf" /> parameter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="haystack">String that will be scanned in</param>
|
||||||
|
/// <param name="anyNotOf">Characters to not look for in the scanned string</param>
|
||||||
|
/// <param name="startIndex">
|
||||||
|
/// Index of the character in the haystack at which to start scanning
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The index of the first occurence of a character not in the
|
||||||
|
/// <see paramref="anyNotOf" /> array or -1 if all characters in the string were
|
||||||
|
/// present in the <see paramref="anyNotOf" /> array.
|
||||||
|
/// </returns>
|
||||||
|
public static int IndexNotOfAny(string haystack, char[] anyNotOf, int startIndex) {
|
||||||
|
return IndexNotOfAny(haystack, anyNotOf, startIndex, haystack.Length - startIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches for the first occurence of a character other than the characters
|
||||||
|
/// listed in the <see paramref="anyNotOf" /> parameter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="haystack">String that will be scanned in</param>
|
||||||
|
/// <param name="anyNotOf">Characters to not look for in the scanned string</param>
|
||||||
|
/// <param name="startIndex">
|
||||||
|
/// Index of the character in the haystack at which to start scanning
|
||||||
|
/// </param>
|
||||||
|
/// <param name="count">Number of characters in the haystack to scan</param>
|
||||||
|
/// <returns>
|
||||||
|
/// The index of the first occurence of a character not in the
|
||||||
|
/// <see paramref="anyNotOf" /> array or -1 if all characters in the string were
|
||||||
|
/// present in the <see paramref="anyNotOf" /> array.
|
||||||
|
/// </returns>
|
||||||
|
public static int IndexNotOfAny(
|
||||||
|
string haystack, char[] anyNotOf, int startIndex, int count
|
||||||
|
) {
|
||||||
|
int anyLength = anyNotOf.Length;
|
||||||
|
|
||||||
|
count += startIndex;
|
||||||
|
while(startIndex < count) {
|
||||||
|
char character = haystack[startIndex];
|
||||||
|
|
||||||
|
for(int anyIndex = 0; anyIndex < anyLength; ++anyIndex) {
|
||||||
|
if(character != anyNotOf[anyIndex]) {
|
||||||
|
return startIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
++startIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches backwards for the first occurence of a character other than the
|
||||||
|
/// characters listed in the <see cref="anyNotOf" /> parameter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="haystack">String that will be scanned in</param>
|
||||||
|
/// <param name="anyNotOf">Characters to not look for in the scanned string</param>
|
||||||
|
/// <returns>
|
||||||
|
/// The index of the first occurence of a character not in the
|
||||||
|
/// <see paramref="anyNotOf" /> array or -1 if all characters in the string were
|
||||||
|
/// present in the <see paramref="anyNotOf" /> array.
|
||||||
|
/// </returns>
|
||||||
|
public static int LastIndexNotOfAny(string haystack, char[] anyNotOf) {
|
||||||
|
return LastIndexNotOfAny(haystack, anyNotOf, haystack.Length - 1, haystack.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches backwards for the first occurence of a character other than the
|
||||||
|
/// characters listed in the <see paramref="anyNotOf" /> parameter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="haystack">String that will be scanned in</param>
|
||||||
|
/// <param name="anyNotOf">Characters to not look for in the scanned string</param>
|
||||||
|
/// <param name="startIndex">
|
||||||
|
/// Index of the character in the haystack at which to start scanning
|
||||||
|
/// </param>
|
||||||
|
/// <returns>
|
||||||
|
/// The index of the first occurence of a character not in the
|
||||||
|
/// <see paramref="anyNotOf" /> array or -1 if all characters in the string were
|
||||||
|
/// present in the <see paramref="anyNotOf" /> array.
|
||||||
|
/// </returns>
|
||||||
|
public static int LastIndexNotOfAny(string haystack, char[] anyNotOf, int startIndex) {
|
||||||
|
return LastIndexNotOfAny(haystack, anyNotOf, startIndex, startIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Searches backwards for the first occurence of a character other than the
|
||||||
|
/// characters listed in the <see paramref="anyNotOf" /> parameter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="haystack">String that will be scanned in</param>
|
||||||
|
/// <param name="anyNotOf">Characters to not look for in the scanned string</param>
|
||||||
|
/// <param name="startIndex">
|
||||||
|
/// Index of the character in the haystack at which to start scanning
|
||||||
|
/// </param>
|
||||||
|
/// <param name="count">Number of characters in the haystack to scan</param>
|
||||||
|
/// <returns>
|
||||||
|
/// The index of the first occurence of a character not in the
|
||||||
|
/// <see paramref="anyNotOf" /> array or -1 if all characters in the string were
|
||||||
|
/// present in the <see paramref="anyNotOf" /> array.
|
||||||
|
/// </returns>
|
||||||
|
public static int LastIndexNotOfAny(
|
||||||
|
string haystack, char[] anyNotOf, int startIndex, int count
|
||||||
|
) {
|
||||||
|
int anyLength = anyNotOf.Length;
|
||||||
|
|
||||||
|
count = startIndex - count;
|
||||||
|
while(startIndex > count) {
|
||||||
|
char character = haystack[startIndex];
|
||||||
|
|
||||||
|
for(int anyIndex = 0; anyIndex < anyLength; ++anyIndex) {
|
||||||
|
if(character != anyNotOf[anyIndex]) {
|
||||||
|
return startIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
--startIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Nuclex.Support
|
Loading…
Reference in New Issue
Block a user