// MIT License - Copyright (c) 2025 wallstop
// Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE
namespace WallstopStudios.UnityHelpers.Core.Helper
{
using System;
///
/// Utilities for normalizing and sanitizing file paths for Unity projects.
///
///
/// Uses forward slashes to ensure consistency across platforms and AssetDatabase APIs.
///
public static class PathHelper
{
///
/// Normalizes directory separators to forward slashes.
///
/// Any file system path or Unity relative path.
/// The input path with all backslashes replaced by forward slashes; null if input is null.
public static string Sanitize(string path)
{
return path.SanitizePath();
}
///
/// Normalizes directory separators to forward slashes (internal helper).
///
internal static string SanitizePath(this string path)
{
if (path == null)
{
return null;
}
// Avoid unnecessary allocation if path already has forward slashes only
if (path.IndexOf('\\', StringComparison.Ordinal) < 0)
{
return path;
}
return path.Replace('\\', '/');
}
}
}