PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/MSBuild/Microsoft/Build/Shared/ResourceUtilities.cs

#
C# | 113 lines | 105 code | 8 blank | 0 comment | 42 complexity | f1b0963b72e74ffc883be1c71f457bfd MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. namespace Microsoft.Build.Shared
  2. {
  3. using System;
  4. using System.Globalization;
  5. using System.Runtime.InteropServices;
  6. internal static class ResourceUtilities
  7. {
  8. internal static string ExtractMessageCode(bool msbuildCodeOnly, string message, out string code)
  9. {
  10. Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInternalNull(message, "message");
  11. code = null;
  12. int startIndex = 0;
  13. while ((startIndex < message.Length) && char.IsWhiteSpace(message[startIndex]))
  14. {
  15. startIndex++;
  16. }
  17. if (msbuildCodeOnly)
  18. {
  19. if (((((message.Length < (startIndex + 8)) || (message[startIndex] != 'M')) || ((message[startIndex + 1] != 'S') || (message[startIndex + 2] != 'B'))) || (((message[startIndex + 3] < '0') || (message[startIndex + 3] > '9')) || ((message[startIndex + 4] < '0') || (message[startIndex + 4] > '9')))) || (((message[startIndex + 5] < '0') || (message[startIndex + 5] > '9')) || (((message[startIndex + 6] < '0') || (message[startIndex + 6] > '9')) || (message[startIndex + 7] != ':'))))
  20. {
  21. return message;
  22. }
  23. code = message.Substring(startIndex, 7);
  24. startIndex += 8;
  25. }
  26. else
  27. {
  28. int num2 = startIndex;
  29. while (num2 < message.Length)
  30. {
  31. char ch = message[num2];
  32. if (((ch < 'a') || (ch > 'z')) && ((ch < 'A') || (ch > 'Z')))
  33. {
  34. break;
  35. }
  36. num2++;
  37. }
  38. if (num2 == startIndex)
  39. {
  40. return message;
  41. }
  42. int num3 = num2;
  43. while (num3 < message.Length)
  44. {
  45. char ch2 = message[num3];
  46. if ((ch2 < '0') || (ch2 > '9'))
  47. {
  48. break;
  49. }
  50. num3++;
  51. }
  52. if (num3 == num2)
  53. {
  54. return message;
  55. }
  56. if ((num3 == message.Length) || (message[num3] != ':'))
  57. {
  58. return message;
  59. }
  60. code = message.Substring(startIndex, num3 - startIndex);
  61. startIndex = num3 + 1;
  62. }
  63. while ((startIndex < message.Length) && char.IsWhiteSpace(message[startIndex]))
  64. {
  65. startIndex++;
  66. }
  67. if (startIndex < message.Length)
  68. {
  69. message = message.Substring(startIndex, message.Length - startIndex);
  70. }
  71. return message;
  72. }
  73. internal static string FormatResourceString(string resourceName, params object[] args)
  74. {
  75. string str;
  76. string str2;
  77. return FormatResourceString(out str, out str2, resourceName, args);
  78. }
  79. internal static string FormatResourceString(out string code, out string helpKeyword, string resourceName, params object[] args)
  80. {
  81. helpKeyword = GetHelpKeyword(resourceName);
  82. return ExtractMessageCode(true, FormatString(GetResourceString(resourceName), args), out code);
  83. }
  84. internal static string FormatString(string unformatted, params object[] args)
  85. {
  86. string str = unformatted;
  87. if ((args != null) && (args.Length > 0))
  88. {
  89. str = string.Format(CultureInfo.CurrentCulture, unformatted, args);
  90. }
  91. return str;
  92. }
  93. private static string GetHelpKeyword(string resourceName)
  94. {
  95. return ("MSBuild." + resourceName);
  96. }
  97. internal static string GetResourceString(string resourceName)
  98. {
  99. return Microsoft.Build.Shared.AssemblyResources.GetString(resourceName);
  100. }
  101. internal static void VerifyResourceStringExists(string resourceName)
  102. {
  103. }
  104. }
  105. }