using System.Diagnostics.Contracts; using ToolkitPathUtilities = StardewModdingAPI.Toolkit.Utilities.PathUtilities; namespace StardewModdingAPI.Utilities { /// Provides utilities for normalizing file paths. public static class PathUtilities { /********* ** 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 separators in a file path. /// The file path to normalize. [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); } } }