The Labs \ Source Viewer \ SSCLI \ System.Runtime.Remoting.Channels \ StringHelper

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. //============================================================
  16. //
  17. // File: StringHelper.cs
  18. //
  19. // Summary: Helper methods for strings.
  20. //
  21. //===========================================================
  22. using System;
  23. using System.IO;
  24. using System.Runtime.Remoting;
  25. namespace System.Runtime.Remoting.Channels
  26. {
  27.    
  28.     static internal class StringHelper
  29.     {
  30.         static internal bool StartsWithDoubleUnderscore(string str)
  31.         {
  32.             if (str.Length < 2)
  33.                 return false;
  34.            
  35.             return (str[0] == '_') && (str[1] == '_');
  36.         }
  37.         // StartsWithDoubleUnderscore
  38.         static internal bool StartsWithAsciiIgnoreCasePrefixLower(string str, string asciiPrefix)
  39.         {
  40.             // The caller should know that the arguments aren't null.
  41.            
  42.             int prefixLen = asciiPrefix.Length;
  43.             if (str.Length < prefixLen)
  44.                 return false;
  45.            
  46.             for (int i = 0; i < prefixLen; i++) {
  47.                 // The prefix is assumed to be in lowercase
  48.                 if (ToLowerAscii(str[i]) != asciiPrefix[i]) {
  49.                     return false;
  50.                 }
  51.             }
  52.            
  53.             return true;
  54.         }
  55.         // StartsWithAsciiIgnoreCase
  56.         private static char ToLowerAscii(char ch)
  57.         {
  58.             if ((ch >= 'A') && (ch <= 'Z')) {
  59.                 return (char)(ch + ('a' - 'A'));
  60.             }
  61.            
  62.             return ch;
  63.         }
  64.         // ToLowerAscii
  65.        
  66.     }
  67.     // StringHelper
  68. }
  69. // namespace System.Runtime.Remoting.Channels

Developer Fusion