// 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;
}
}
}