StringUtils.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using COSXML.CosException;
  5. using COSXML.Common;
  6. namespace COSXML.Utils
  7. {
  8. public sealed class StringUtils
  9. {
  10. public static int Compare(string strA, string strB, bool ignoreCase)
  11. {
  12. if (strA == null || strB == null)
  13. {
  14. throw new CosClientException((int)CosClientError.InvalidArgument, "strA = null or strA = null");
  15. }
  16. if (ignoreCase)
  17. {
  18. strA = strA.ToLower();
  19. strB = strB.ToLower();
  20. }
  21. int strALen = strA.Length;
  22. int strBLen = strB.Length;
  23. for (int i = 0, size = strALen > strBLen ? strBLen : strALen; i < size; i++)
  24. {
  25. int temp1 = (int)strA[i];
  26. int temp2 = (int)strB[i];
  27. if (temp1 > temp2)
  28. {
  29. return 1;
  30. }
  31. else
  32. if (temp1 < temp2)
  33. {
  34. return -1;
  35. }
  36. }
  37. if (strALen > strBLen)
  38. {
  39. return 1;
  40. }
  41. if (strALen < strBLen)
  42. {
  43. return -1;
  44. }
  45. return 0;
  46. }
  47. // public static Dictionary<string, string> ParseURL(string url)
  48. // {
  49. // Dictionary<string, string> urlTuple = new Dictionary<string, string>();
  50. // if (String.IsNullOrEmpty(url))
  51. // {
  52. // return null;
  53. // }
  54. // int index = url.IndexOf("://");
  55. // if (index > 0)
  56. // {
  57. // urlTuple.Add("Scheme", url.Substring(0, index));
  58. // }
  59. // else
  60. // {
  61. // throw new ArgumentException("url need start with http:// or https://");
  62. // }
  63. // int tmp = index;
  64. // index = url.IndexOf('/', tmp + 3);
  65. // if (index > 0)
  66. // {
  67. // urlTuple.Add("Host", url.Substring(tmp + 3, index - tmp - 3));
  68. // tmp = index;
  69. // }
  70. // else
  71. // {
  72. // urlTuple.Add("Host", url.Substring(tmp + 3));
  73. // return urlTuple;
  74. // }
  75. // index = url.IndexOf('?', tmp);
  76. // if (index > 0)
  77. // {
  78. // urlTuple.Add("Path", url.Substring(tmp, index - tmp));
  79. // tmp = index;
  80. // }
  81. // else
  82. // {
  83. // urlTuple.Add("Path", url.Substring(tmp));
  84. // return urlTuple;
  85. // }
  86. // index = url.IndexOf("#", tmp + 1);
  87. // if (index > 0)
  88. // {
  89. // urlTuple.Add("Query", url.Substring(tmp + 1, index - tmp - 1));
  90. // tmp = index;
  91. // }
  92. // else
  93. // {
  94. // urlTuple.Add("Query", url.Substring(tmp + 1));
  95. // return urlTuple;
  96. // }
  97. // urlTuple.Add("Fragment", url.Substring(tmp + 1));
  98. // return urlTuple;
  99. // }
  100. }
  101. }