From 244b46cf7f3252d6dc3884ce184be901d1d173e5 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 2 Sep 2018 16:12:29 -0500 Subject: Migrate WixCop into Tools from wix4. --- src/Wixtoolset.Tools.Core/ToolsCommon.cs | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Wixtoolset.Tools.Core/ToolsCommon.cs (limited to 'src/Wixtoolset.Tools.Core/ToolsCommon.cs') diff --git a/src/Wixtoolset.Tools.Core/ToolsCommon.cs b/src/Wixtoolset.Tools.Core/ToolsCommon.cs new file mode 100644 index 00000000..37d89f3c --- /dev/null +++ b/src/Wixtoolset.Tools.Core/ToolsCommon.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Tools.Core +{ + using System; + using System.Text.RegularExpressions; + + /// + /// Common WixTasks utility methods and types. + /// + public static class ToolsCommon + { + /// Metadata key name to turn off harvesting of project references. + public const string DoNotHarvest = "DoNotHarvest"; + + private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]", RegexOptions.Compiled); + private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}", RegexOptions.Compiled); // non 'words' and assorted valid characters + + /// + /// Return an identifier based on passed file/directory name + /// + /// File/directory name to generate identifer from + /// A version of the name that is a legal identifier. + /// This is duplicated from WiX's Common class. + public static string GetIdentifierFromName(string name) + { + string result = IllegalIdentifierCharacters.Replace(name, "_"); // replace illegal characters with "_". + + // MSI identifiers must begin with an alphabetic character or an + // underscore. Prefix all other values with an underscore. + if (AddPrefix.IsMatch(name)) + { + result = String.Concat("_", result); + } + + return result; + } + } +} -- cgit v1.2.3-55-g6feb