From df948d2eab8aef76609ee75424a0e9868849f5b1 Mon Sep 17 00:00:00 2001 From: Markus Ewald Date: Mon, 28 Jul 2008 19:58:15 +0000 Subject: [PATCH] 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 --- Nuclex.Support (x86).csproj | 2 + Source/FloatHelper.Test.cs | 22 ++++- Source/FloatHelper.cs | 22 ++++- Source/IntegerHelper.Test.cs | 22 ++++- Source/IntegerHelper.cs | 22 ++++- Source/PathHelper.cs | 20 +++++ Source/StringHelper.Test.cs | 40 +++++++++ Source/StringHelper.cs | 169 +++++++++++++++++++++++++++++++++++ 8 files changed, 315 insertions(+), 4 deletions(-) create mode 100644 Source/StringHelper.Test.cs create mode 100644 Source/StringHelper.cs diff --git a/Nuclex.Support (x86).csproj b/Nuclex.Support (x86).csproj index d3bcbc8..4f22580 100644 --- a/Nuclex.Support (x86).csproj +++ b/Nuclex.Support (x86).csproj @@ -177,6 +177,8 @@ + + diff --git a/Source/FloatHelper.Test.cs b/Source/FloatHelper.Test.cs index bae8a02..01402ec 100644 --- a/Source/FloatHelper.Test.cs +++ b/Source/FloatHelper.Test.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; #if UNITTEST diff --git a/Source/FloatHelper.cs b/Source/FloatHelper.cs index e6e568b..431eb96 100644 --- a/Source/FloatHelper.cs +++ b/Source/FloatHelper.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.Runtime.InteropServices; diff --git a/Source/IntegerHelper.Test.cs b/Source/IntegerHelper.Test.cs index de6b9f0..438b66e 100644 --- a/Source/IntegerHelper.Test.cs +++ b/Source/IntegerHelper.Test.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 NUnit.Framework; diff --git a/Source/IntegerHelper.cs b/Source/IntegerHelper.cs index 840d744..6b35e52 100644 --- a/Source/IntegerHelper.cs +++ b/Source/IntegerHelper.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; namespace Nuclex.Support { diff --git a/Source/PathHelper.cs b/Source/PathHelper.cs index e1c6147..38ba520 100644 --- a/Source/PathHelper.cs +++ b/Source/PathHelper.cs @@ -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.Collections.Generic; using System.Text; diff --git a/Source/StringHelper.Test.cs b/Source/StringHelper.Test.cs new file mode 100644 index 0000000..5e18edc --- /dev/null +++ b/Source/StringHelper.Test.cs @@ -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 { + + /// Unit Test for the string helper class + [TestFixture] + public class PathHelperTest { + + + } + +} // namespace Nuclex.Support + +#endif // UNITTEST diff --git a/Source/StringHelper.cs b/Source/StringHelper.cs new file mode 100644 index 0000000..75d60d7 --- /dev/null +++ b/Source/StringHelper.cs @@ -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 { + + /// Helper routines for working with strings + public static class StringHelper { + + /// + /// Searches for the first occurence of a character other than the characters + /// listed in the parameter + /// + /// String that will be scanned in + /// Characters to not look for in the scanned string + /// + /// The index of the first occurence of a character not in the + /// array or -1 if all characters in the string were + /// present in the array. + /// + public static int IndexNotOfAny(string haystack, char[] anyNotOf) { + return IndexNotOfAny(haystack, anyNotOf, 0, haystack.Length); + } + + /// + /// Searches for the first occurence of a character other than the characters + /// listed in the parameter + /// + /// String that will be scanned in + /// Characters to not look for in the scanned string + /// + /// Index of the character in the haystack at which to start scanning + /// + /// + /// The index of the first occurence of a character not in the + /// array or -1 if all characters in the string were + /// present in the array. + /// + public static int IndexNotOfAny(string haystack, char[] anyNotOf, int startIndex) { + return IndexNotOfAny(haystack, anyNotOf, startIndex, haystack.Length - startIndex); + } + + /// + /// Searches for the first occurence of a character other than the characters + /// listed in the parameter + /// + /// String that will be scanned in + /// Characters to not look for in the scanned string + /// + /// Index of the character in the haystack at which to start scanning + /// + /// Number of characters in the haystack to scan + /// + /// The index of the first occurence of a character not in the + /// array or -1 if all characters in the string were + /// present in the array. + /// + 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; + } + + /// + /// Searches backwards for the first occurence of a character other than the + /// characters listed in the parameter + /// + /// String that will be scanned in + /// Characters to not look for in the scanned string + /// + /// The index of the first occurence of a character not in the + /// array or -1 if all characters in the string were + /// present in the array. + /// + public static int LastIndexNotOfAny(string haystack, char[] anyNotOf) { + return LastIndexNotOfAny(haystack, anyNotOf, haystack.Length - 1, haystack.Length); + } + + /// + /// Searches backwards for the first occurence of a character other than the + /// characters listed in the parameter + /// + /// String that will be scanned in + /// Characters to not look for in the scanned string + /// + /// Index of the character in the haystack at which to start scanning + /// + /// + /// The index of the first occurence of a character not in the + /// array or -1 if all characters in the string were + /// present in the array. + /// + public static int LastIndexNotOfAny(string haystack, char[] anyNotOf, int startIndex) { + return LastIndexNotOfAny(haystack, anyNotOf, startIndex, startIndex + 1); + } + + /// + /// Searches backwards for the first occurence of a character other than the + /// characters listed in the parameter + /// + /// String that will be scanned in + /// Characters to not look for in the scanned string + /// + /// Index of the character in the haystack at which to start scanning + /// + /// Number of characters in the haystack to scan + /// + /// The index of the first occurence of a character not in the + /// array or -1 if all characters in the string were + /// present in the array. + /// + 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