using System.Diagnostics.Contracts; using ToolkitPathUtilities = StardewModdingAPI.Toolkit.Utilities.PathUtilities; namespace StardewModdingAPI.Utilities { /// Provides utilities for normalizing file paths. public static class PathUtilities { /********* ** Accessors *********/ /// The preferred directory separator character in an asset key. public static char PreferredAssetSeparator { get; } = ToolkitPathUtilities.PreferredAssetSeparator; /********* ** Public methods *********/ /// Get the segments from a path (e.g. /usr/bin/example => usr, bin, and example). /// The path to split. /// The number of segments to match. Any additional segments will be merged into the last returned part. [Pure] public static string[] GetSegments(string path, int? limit = null) { return ToolkitPathUtilities.GetSegments(path, limit); } /// Normalize an asset name to match how MonoGame's content APIs would normalize and cache it. /// The asset name to normalize. public static string NormalizeAssetName(string assetName) { return ToolkitPathUtilities.NormalizeAssetName(assetName); } /// Normalize separators in a file path for the current platform. /// The file path to normalize. /// This should only be used for file paths. For asset names, use instead. [Pure] public static string NormalizePath(string path) { return ToolkitPathUtilities.NormalizePath(path); } /// Get whether a path is relative and doesn't try to climb out of its containing folder (e.g. doesn't contain ../). /// The path to check. [Pure] public static bool IsSafeRelativePath(string path) { return ToolkitPathUtilities.IsSafeRelativePath(path); } /// Get whether a string is a valid 'slug', containing only basic characters that are safe in all contexts (e.g. filenames, URLs, etc). /// The string to check. [Pure] public static bool IsSlug(string str) { return ToolkitPathUtilities.IsSlug(str); } } }