using System.Linq; using System.Text.RegularExpressions; namespace MCPForUnity.Editor.Helpers { /// /// Utility class for converting between naming conventions (snake_case, camelCase). /// Consolidates previously duplicated implementations from ToolParams, ManageVFX, /// BatchExecute, CommandRegistry, and ToolDiscoveryService. /// public static class StringCaseUtility { /// /// Converts a camelCase string to snake_case. /// Example: "searchMethod" -> "search_method", "param1Value" -> "param1_value" /// /// The camelCase string to convert /// The snake_case equivalent, or original string if null/empty public static string ToSnakeCase(string str) { if (string.IsNullOrEmpty(str)) return str; return Regex.Replace(str, "([a-z0-9])([A-Z])", "$1_$2").ToLowerInvariant(); } /// /// Converts a snake_case string to camelCase. /// Example: "search_method" -> "searchMethod" /// /// The snake_case string to convert /// The camelCase equivalent, or original string if null/empty or no underscores public static string ToCamelCase(string str) { if (string.IsNullOrEmpty(str) || !str.Contains("_")) return str; var parts = str.Split('_'); if (parts.Length == 0) return str; // First part stays lowercase, rest get capitalized var first = parts[0]; var rest = string.Concat(parts.Skip(1).Select(part => string.IsNullOrEmpty(part) ? "" : char.ToUpperInvariant(part[0]) + part.Substring(1))); return first + rest; } } }