|
@@ -25,8 +25,8 @@ package haxe.io;
|
|
|
This class provides a convenient way of working with paths. It supports the
|
|
|
common path formats:
|
|
|
|
|
|
- - directory1/directory2/filename.extension
|
|
|
- - directory1\directory2\filename.extension
|
|
|
+ - `directory1/directory2/filename.extension`
|
|
|
+ - `directory1\directory2\filename.extension`
|
|
|
**/
|
|
|
class Path {
|
|
|
|
|
@@ -38,7 +38,7 @@ class Path {
|
|
|
|
|
|
Does not end with a `/` or `\` separator.
|
|
|
|
|
|
- If the path has no directory, the value is null.
|
|
|
+ If the path has no directory, the value is `null`.
|
|
|
**/
|
|
|
public var dir : String;
|
|
|
|
|
@@ -47,8 +47,8 @@ class Path {
|
|
|
|
|
|
This is the part of the part between the directory and the extension.
|
|
|
|
|
|
- If there is no file name, e.g. for ".htaccess" or "/dir/", the value
|
|
|
- is the empty String "".
|
|
|
+ If there is no file name, e.g. for `".htaccess"` or `"/dir/"`, the value
|
|
|
+ is the empty String `""`.
|
|
|
**/
|
|
|
public var file : String;
|
|
|
|
|
@@ -58,19 +58,19 @@ class Path {
|
|
|
It is separated from the file name by a dot. This dot is not part of
|
|
|
the extension.
|
|
|
|
|
|
- If the path has no extension, the value is null.
|
|
|
+ If the path has no extension, the value is `null`.
|
|
|
**/
|
|
|
public var ext : String;
|
|
|
|
|
|
/**
|
|
|
- True if the last directory separator is a backslash, false otherwise.
|
|
|
+ `true` if the last directory separator is a backslash, `false` otherwise.
|
|
|
**/
|
|
|
public var backslash : Bool;
|
|
|
|
|
|
/**
|
|
|
- Creates a new Path instance by parsing `path`.
|
|
|
+ Creates a new `Path` instance by parsing `path`.
|
|
|
|
|
|
- Path information can be retrieved by accessing the dir, file and ext
|
|
|
+ Path information can be retrieved by accessing the `dir`, `file` and `ext`
|
|
|
properties.
|
|
|
**/
|
|
|
public function new( path : String ) {
|
|
@@ -104,12 +104,12 @@ class Path {
|
|
|
/**
|
|
|
Returns a String representation of `this` path.
|
|
|
|
|
|
- If `this.backslash` is true, backslash is used as directory separator,
|
|
|
+ If `this.backslash` is `true`, backslash is used as directory separator,
|
|
|
otherwise slash is used. This only affects the separator between
|
|
|
`this.dir` and `this.file`.
|
|
|
|
|
|
- If `this.directory` or `this.extension` is null, their representation
|
|
|
- is the empty String "".
|
|
|
+ If `this.directory` or `this.extension` is `null`, their representation
|
|
|
+ is the empty String `""`.
|
|
|
**/
|
|
|
public function toString() : String {
|
|
|
return (if( dir == null ) "" else dir + if( backslash ) "\\" else "/") + file + (if( ext == null ) "" else "." + ext);
|
|
@@ -118,7 +118,7 @@ class Path {
|
|
|
/**
|
|
|
Returns the String representation of `path` without the file extension.
|
|
|
|
|
|
- If `path` is null, the result is unspecified.
|
|
|
+ If `path` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function withoutExtension( path : String ) : String {
|
|
|
var s = new Path(path);
|
|
@@ -129,7 +129,7 @@ class Path {
|
|
|
/**
|
|
|
Returns the String representation of `path` without the directory.
|
|
|
|
|
|
- If `path` is null, the result is unspecified.
|
|
|
+ If `path` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function withoutDirectory( path ) : String {
|
|
|
var s = new Path(path);
|
|
@@ -140,9 +140,9 @@ class Path {
|
|
|
/**
|
|
|
Returns the directory of `path`.
|
|
|
|
|
|
- If the directory is null, the empty String `""` is returned.
|
|
|
+ If the directory is `null`, the empty String `""` is returned.
|
|
|
|
|
|
- If `path` is null, the result is unspecified.
|
|
|
+ If `path` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function directory( path ) : String {
|
|
|
var s = new Path(path);
|
|
@@ -154,9 +154,9 @@ class Path {
|
|
|
/**
|
|
|
Returns the extension of `path`.
|
|
|
|
|
|
- If the extension is null, the empty String `""` is returned.
|
|
|
+ If the extension is `null`, the empty String `""` is returned.
|
|
|
|
|
|
- If `path` is null, the result is unspecified.
|
|
|
+ If `path` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function extension( path ) : String {
|
|
|
var s = new Path(path);
|
|
@@ -170,7 +170,7 @@ class Path {
|
|
|
|
|
|
If `path` has no extension, `ext` is added as extension.
|
|
|
|
|
|
- If `path` or `ext` are null, the result is unspecified.
|
|
|
+ If `path` or `ext` are `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function withExtension( path, ext ) : String {
|
|
|
var s = new Path(path);
|
|
@@ -184,7 +184,7 @@ class Path {
|
|
|
If `paths` is empty, the empty String `""` is returned. Otherwise the
|
|
|
paths are joined with a slash between them.
|
|
|
|
|
|
- If `paths` is null, the result is unspecified.
|
|
|
+ If `paths` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function join(paths:Array<String>) : String {
|
|
|
var paths = paths.filter(function(s) return s != null && s != "");
|
|
@@ -200,12 +200,12 @@ class Path {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- Normalize a given `path` (e.g. make '/usr/local/../lib' to '/usr/lib').
|
|
|
+ Normalize a given `path` (e.g. turn `'/usr/local/../lib'` into `'/usr/lib'`).
|
|
|
|
|
|
- Also replaces backslashes \ with slashes / and afterwards turns
|
|
|
+ Also replaces backslashes `\` with slashes `/` and afterwards turns
|
|
|
multiple slashes into a single one.
|
|
|
|
|
|
- If `path` is null, the result is unspecified.
|
|
|
+ If `path` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function normalize(path : String) : String {
|
|
|
var slash = "/";
|
|
@@ -255,7 +255,7 @@ class Path {
|
|
|
is appended to `path`. In particular, this applies to the empty String
|
|
|
`""`.
|
|
|
|
|
|
- If `path` is null, the result is unspecified.
|
|
|
+ If `path` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
public static function addTrailingSlash( path : String ) : String {
|
|
|
if (path.length == 0)
|
|
@@ -279,7 +279,7 @@ class Path {
|
|
|
Otherwise the substring of `path` excluding the trailing slashes or
|
|
|
backslashes is returned.
|
|
|
|
|
|
- If `path` is null, the result is unspecified.
|
|
|
+ If `path` is `null`, the result is unspecified.
|
|
|
**/
|
|
|
@:require(haxe_ver >= 3.1)
|
|
|
public static function removeTrailingSlashes ( path : String ) : String {
|
|
@@ -293,7 +293,7 @@ class Path {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- Returns true if the path is an absolute path, and false otherwise.
|
|
|
+ Returns `true` if the path is an absolute path, and `false` otherwise.
|
|
|
**/
|
|
|
@:require(haxe_ver >= 3.2)
|
|
|
public static function isAbsolute ( path : String ) : Bool {
|