/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of xAPI4Unity. */ #if UNITY_EDITOR using System; using System.Linq; namespace xAPI4Unity.Editor.Parser { /// /// Class with extension functions for strings /// internal static class StringExt { public static string ToString(object[] values) => $"[{string.Join(",", values)}]"; /// /// Capitalizes the first letter of a string /// /// String to capitalize /// Capitalized string public static string Capitalize(this string value) { if (value == "") { throw new ArgumentException($"{nameof(value)} cannot be empty", nameof(value)); } return value.First().ToString().ToUpper() + value.Substring(1); } /// /// Clears a name string of special characters that cannot be used /// /// String to clear /// Cleared string with replaced or removed characters public static string ClearName(this string value) { var name = value .Replace(' ', '_') .Replace(",", "") .Replace(".", "") .Replace("(", "") .Replace(")", "") .Replace("ä", "ae") .Replace("ö", "oe") .Replace("ü", "ue") .Replace("Ä", "Ae") .Replace("Ö", "Oe") .Replace("Ü", "Ue") .Replace("ß", "ss"); var firstLetter = name[0]; return (!char.IsLetter(firstLetter) ? "_" : "") + char.ToLowerInvariant(firstLetter) + name.Substring(1); } /// /// Clears a string of characters that must be escaped /// /// String to clear /// Cleared string with replaced characters public static string ClearString(this string value) { return value .Replace("\"", "\\\""); } } } #endif