internal static string GetNormalizedTaxonomyName(string name, string argumentName) { ToolkitUtilities.ConfirmNotNull(name, argumentName); string normalizedName = Regex.Replace(name, @"\s+", " "); normalizedName = normalizedName.Replace('&', (char)0xff06).Replace('"', (char)0xff02); if (normalizedName.Length > 255) { throw new ArgumentException("The name length cannot exceed 255 characters: \"" + normalizedName + "\""); } normalizedName = normalizedName.Trim(); if (normalizedName.Length == 0) { throw new ArgumentException("The name cannot be empty"); } if (!ToolkitUtilities.validNameRegex.IsMatch(normalizedName)) { throw new ArgumentException("The name contains invalid characters: \"" + normalizedName + "\""); } return(normalizedName); }
/// <summary> /// TaxonomyItem.NormalizeName() replaces ampersands with a Unicode character. This form is /// used throughout the Taxonomy API and should be used in code, but when displayed in the /// UI it looks wrong in many fonts. You can use GetDenormalizedTaxonomyNameForDisplay() /// to convert it back to the regular ampersand. /// </summary> public static string GetDenormalizedTaxonomyNameForDisplay(string name) { ToolkitUtilities.ConfirmNotNull(name, "name"); return(name.Replace((char)0xff06, '&')); }