Note Heading

Index

Sections

classAbsolutePath - START

Code

var classAbsolutePath /*: Function*/ = (function()
{

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_start>
NAME <classAbsolutePath - START>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <>

classAbsolutePath(path : String [, type : int, separator : String]) : void

Code

function classAbsolutePath(
	path /*: String*/,
	type /*: int*/,
	separator /*: String*/
) /*: void*/
{	
	this.type /*: int*/; 
	this.path /*: String*/;
	this.separator /*: String*/;

	this.initialise(path, type, separator);
}

var constr /*: Function*/ = classAbsolutePath;

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_constructor>
NAME <classAbsolutePath>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@classAbsolutePath.initialise
>

initialise(path: String [, type : int, separator : String]) : void, throws TypeError, SeparatorError, ParseError

Code

function initialise(
	path /*: String*/,
	type /*: int*/,
	separator /*: String*/
) /*: void*/
{
	/* Trim */
	path = String_Trim(String(path));
	
	/* TRY TO GUESS TYPE */
	if (!type)
	{
		if (WIN_PATH.test(path) || WIN_DRIVE.test(path))
		{
			type = TYPE_WIN;
		}
		else if (WIN_UNC_PATH.test(path) || WIN_UNC_DRIVE.test(path))
		{
			type = TYPE_WIN_UNC;
		}
		else if (UNIX_PATH.test(path))
		{
			type = TYPE_UNIX;
		}
		else
		{
			throw new ParseError("Supplied path is not a valid or recognised path - " + path);
		}
	}
	else
	{
		if (!isValidPath(path, type))
		{
			throw new ParseError("Supplied path is not a valid or recognised path - " + path);			
		}
	}

	/* Separator */
	if (separator)
	{
		if (type == TYPE_UNIX && separator != "\/")
		{
			throw new SeparatorError("Invalid separator specified for UNIX path type - " + separator);
		}
		else if (type != TYPE_UNIX && !/\/|\\/.test(separator))
		{
			throw new SeparatorError("Invalid separator specified for WIN or WIN_UNC path type - " + separator);
		}
	}
	else
	{
		if (type == TYPE_WIN || type == TYPE_WIN_UNC)
		{
			separator = "\\";
		}
		else if (type == TYPE_UNIX)
		{
			separator = "\/";
		}
	}


	if (type == TYPE_WIN || type == TYPE_WIN_UNC)
	{
		path = path.replace(/\/|\\/g, separator);
	}

	/* No end separator except for root folder */
	if (type == TYPE_WIN)
	{
		if (WIN_DRIVE.test(path))
		{
			path = path + separator;
		}
		else if (!WIN_ROOTFOLDER.test(path) && /(\/|\\)$/.test(path))
		{
			path = String_RemoveLastChar(path);
		}
	}
	else if (type == TYPE_WIN_UNC)
	{
		if (WIN_UNC_DRIVE.test(path))
		{
			path = path + separator;
		}
		else if (!WIN_UNC_ROOTFOLDER.test(path) && /(\/|\\)$/.test(path))
		{
			path = String_RemoveLastChar(path);
		}
	}
	else if (type == TYPE_UNIX && /[^\/]\/$/.test(path))
	{
		path = String_RemoveLastChar(path);
	}


	/* Set Properties */
	this.type = type;
	this.path = path;
	this.separator = separator;

	//alert(this.type + " | " + this.path + " | " + this.separator);
}

AddMethod(constr, initialise);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_initialise>
NAME <initialise>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@util.String_RemoveLastChar
@util.String_Trim
@classAbsolutePath.ParseError
@classAbsolutePath.TypeError
@classAbsolutePath.SeparatorError
@classAbsolutePath.isValidPath
>

TYPE

Code

constr.TYPE_WIN 	/*: int*/ = 1;
constr.TYPE_WIN_UNC 	/*: int*/ = 2;
constr.TYPE_UNIX	/*: int*/ = 3;

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_static_constants>
NAME <TYPE>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <

>

isValidName(name : String, type : int) : Boolean, throws TypeError

Code

function isValidName(
	name /*: String*/,
	type /*: int*/
) /*: Boolean, throws TypeError*/
{
	switch(type)
	{
		case TYPE_WIN:
			return WIN_NAME.test(name);
			break;

		case TYPE_WIN_UNC:
			return WIN_UNC_NAME.test(name);
			break;
				
		case TYPE_UNIX:
			return UNIX_NAME.test(name);
			break;

		default:
			throw new TypeError("Unknown type - " + type);
			break;
	}

	return false;
}

constr.isValidName = isValidName;
isValidName.name = isValidName;

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_static_method>
NAME <isValidName>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@classAbsolutePath.TypeError
@classAbsolutePath.isValidName
>

isValidPath(path : String, type : int) : Boolean, throws TypeError

Code

function isValidPath(
	path /*: String*/,
	type /*: int*/
) /*: Boolean, throws TypeError*/
{
	switch(type)
	{
		case TYPE_WIN:
			return WIN_PATH.test(path) || WIN_DRIVE.test(path);
			break;

		case TYPE_WIN_UNC:
			return WIN_UNC_PATH.test(path)  || WIN_UNC_DRIVE.test(path);
			break;
				
		case TYPE_UNIX:
			return UNIX_PATH.test(path);
			break;

		default:
			throw new TypeError("Unknown type number - " + type);
			break;
	}

	return false;
}

constr.isValidPath = isValidPath;
isValidPath.name = isValidPath;

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_static_method>
NAME <isValidPath>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@classAbsolutePath.TypeError
@classAbsolutePath.isValidPath
>

appendNewTarget(name : String) : Boolean, throws TypeError, ParseError

Code

function appendNewTarget(
	name /*: String*/
) /*: Boolean*/
{
	name = String_Trim(name);

	if (!isValidName(name, this.type))
	{
		throw new ParseError("Invalid name - " + name);
	}

	if (String_LastChar(this.path) != this.separator)
	{
		this.path = this.path + this.separator + name;
	}
	else
	{
		this.path = this.path + name;
	}

	return true;
}

AddMethod(constr, appendNewTarget);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <appendNewTarget>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@util.String_LastChar
@util.String_Trim
@classAbsolutePath.appendNewTarget
@classAbsolutePath.isValidName
>

getTargetName() : String, throws TypeError

Code

function getTargetName() /*: String*/
{
	var execResult /*: Array.<String>*/ = this.execPath(this.path);

	if (!execResult)
	{
		throw new ParseError("Invalid path - " + this.path);
	}

	if (!execResult.TargetName)
	{
		return "ROOT_FOLDER";  // Should be the root folder
 	}

	return execResult.TargetName;
}

AddMethod(constr, getTargetName);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getTargetName>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@classAbsolutePath.execPath
@classAbsolutePath.getTargetName
>

getTargetBaseName() : String, throws TypeError

Code

function getTargetBaseName() /*: String*/
{
	var targetName /*: String*/ = this.getTargetName();

	if (targetName == "")
	{
		return "ROOT_FOLDER"; // Should be the root folder
	}

	var execResult /*: Array.<String>*/ = this.execName(targetName);

	if (!execResult)
	{
		throw new ParseError("Invalid name - " + targetName);
	}

	return execResult.BaseName;
}

AddMethod(constr, getTargetBaseName);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getTargetBaseName>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@classAbsolutePath.execName
@classAbsolutePath.getTargetBaseName
@classAbsolutePath.getTargetName
>

getTargetExtension() : String, throws TypeError

Code

function getTargetExtension() /*: String*/
{
	var targetName /*: String*/ = this.getTargetName();

	if (targetName == "")
	{
		return "";
	}

	var execResult /*: Array.<String>*/ = this.execName(targetName);

	if (!execResult)
	{
		throw new ParseError("Invalid name - " + targetName);
	}

	return execResult.Extension;
}

AddMethod(constr, getTargetExtension);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getTargetExtension>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@classAbsolutePath.execName
@classAbsolutePath.getTargetExtension
@classAbsolutePath.getTargetName
>

getParentFolder() : classAbsolutePath, throws TypeError, ParseError

Code

function getParentFolder() /*: classAbsolutePath*/
{
	if (this.isRootFolder())
	{
		return null;
	}

	var execResult /*: Array.<String>*/ = this.execPath(this.path);

	if (!execResult)
	{
		throw new ParseError("Invalid path : " + this.path);
	}

	var rootFolderPath /*: String*/ = execResult.RootFolderPath;
	var folderChain /*: String*/ = execResult.FolderChain;

	folderChain = String_RemoveLastChar(folderChain);

	var path /*: String*/ = rootFolderPath + folderChain;

	return new classAbsolutePath(path);
}

AddMethod(constr, getParentFolder);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getParentFolder>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@util.String_RemoveLastChar
@classAbsolutePath.execPath
@classAbsolutePath.getParentFolder
@classAbsolutePath.isRootFolder
>

getParentFolderName() : String, throws TypeError, ParseError

Code

function getParentFolderName() /*: String*/
{
	var path /*: classAbsolutePath */ = this.getParentFolder();

	if (!path)
	{
		return "";
	}

	return path.getTargetName();
}

AddMethod(constr, getParentFolderName);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getParentFolderName>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.getParentFolder
@classAbsolutePath.getParentFolderName
@classAbsolutePath.getTargetName
>

getParentFolders() : Array.<classAbsolutePath>, throws TypeError, ParseError

Code

function getParentFolders() /*: Array.<classAbsolutePath>*/
{
	var folders /*: Array.<classAbsolutePath*/ = [];
	var parent /*: classAbsolutePath*/ = this.getParentFolder();

	var o = 20;

	while(parent && o--)
	{
		folders.push(parent);	
		parent = parent.getParentFolder();
	}

	folders.reverse();

	return folders;
}

AddMethod(constr, getParentFolders);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getParentFolders>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath
@classAbsolutePath.getParentFolder
@classAbsolutePath.getParentFolders
>

getParentFolderNames() : Array.<String>, throws TypeError, ParseError

Code

function getParentFolderNames() /*: Array.<String>*/
{
	var folders /*: Array.<String>*/ = [];
	var parent /*: classAbsolutePath*/ = this.getParentFolder();
	
	var o = 20;

	while(parent && o--)
	{
		folders.push(parent.getTargetName());
		parent = parent.getParentFolder();
	}

	folders.reverse();

	return folders;
}

AddMethod(constr, getParentFolderNames);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getParentFolderNames>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.getParentFolder
@classAbsolutePath.getParentFolderNames
@classAbsolutePath.getTargetName
>

isRootFolder() : Boolean, throws TypeError

Code

function isRootFolder() /*: Boolean*/
{
	if (this.type == TYPE_WIN)
	{
		return WIN_ROOTFOLDER.test(this.path);
	}
	else if (this.type == TYPE_WIN_UNC)
	{
		return WIN_UNC_ROOTFOLDER.test(this.path);
	}
	else if (this.type == TYPE_UNIX)
	{
		return this.path == "/";
	}

	throw new TypeError("Unknown type - " + this.type);
}

AddMethod(constr, isRootFolder);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <isRootFolder>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.TypeError
@classAbsolutePath.isRootFolder
>

getRootFolder() : classAbsolutePath, throws TypeError, ParseError

Code

function getRootFolder() /*: classAbsolutePath*/
{
	var execResult /*: Array*/;

	switch(this.type)
	{
		case TYPE_WIN:
			execResult = WIN_ROOTFOLDER_STUB.exec(this.path);
			break;

		case TYPE_WIN_UNC:
			execResult = WIN_UNC_ROOTFOLDER_STUB.exec(this.path);
			break;

		case TYPE_UNIX:
			execResult = UNIX_ROOTFOLDER_STUB.exec(this.path);
			break;

		default:
			throw new TypeError("Invalid type - " + this.type);
			break;
	}

	if (!execResult)
	{
		throw new ParseError("Invalid path - " + this.path);
	}

	return new classAbsolutePath(execResult[0]);
}

AddMethod(constr, getRootFolder);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getRootFolder>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@classAbsolutePath.TypeError
@classAbsolutePath.getRootFolder
>

toString(appendSeparator : String) : String

Code

function toStr(
	appendSeparator /*: String*/
) /*: String*/
{
	if (appendSeparator && String_LastChar(this.path) != this.separator)
	{
		return this.path + this.separator;
	}
	else
	{
		return this.path;
	}
}

AddMethod(constr, toStr, "toString");

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <toString>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@util.String_LastChar
>

getVolumeName() : String, throws TypeError, ParseError

Code

function getVolumeName() /*: String*/
{
	var execResult /*: Array*/;

	if (this.type == TYPE_WIN)
	{
		execResult = WIN_DRIVE_STUB.exec(this.path);

		if (!execResult)
		{
			throw new ParseError("Invalid path - " + this.path);
		}

		return execResult.DriveLetter;
	}
	else if (this.type == TYPE_WIN_UNC)
	{
		execResult = WIN_UNC_DRIVE_STUB.exec(this.path);

		if (!execResult)
		{
			throw new ParseError("Invalid path - " + this.path);
		}

		return execResult[0];
	}
	else if (this.type == TYPE_UNIX)
	{
		execResult = UNIX_VOLUME_NAME.exec(this.path);

		if (!execResult)
		{
			return "";
		}

		return execResult.VolumeName;
	}
}

AddMethod(constr, getVolumeName);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getVolumeName>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@classAbsolutePath.getVolumeName
>

getVolumePath() : String, throws TypeError, ParseError

Code

function getVolumePath() /*: String*/
{
	var execResult /*: Array*/;

	if (this.type == TYPE_WIN)
	{
		execResult = WIN_DRIVE_STUB.exec(this.path);

		if (!execResult)
		{
			throw new ParseError("Invalid path - " + this.path);
		}

		return execResult[0];
	}
	else if (this.type == TYPE_WIN_UNC)
	{
		execResult = WIN_UNC_DRIVE_STUB.exec(this.path);

		if (!execResult)
		{
			throw new ParseError("Invalid path - " + this.path);
		}

		return execResult[0];
	}
	else if (this.type == TYPE_UNIX)
	{
		execResult = UNIX_VOLUME_NAME.exec(this.path);

		if (!execResult)
		{
			return "";
		}

		return execResult[0];
	}
}

AddMethod(constr, getVolumePath);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getVolumePath>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@classAbsolutePath.getVolumePath
>

getVolumeRootFolder() : String, throws TypeError, ParseError

Code

function getVolumeRootFolder() /*: String*/
{
	var execResult /*: Array*/;

	if (this.type == TYPE_WIN)
	{
		execResult = WIN_DRIVE_STUB.exec(this.path);

		if (!execResult)
		{
			throw new ParseError("Invalid path - " + this.path);
		}

		return execResult[0] + this.separator;
	}
	else if (this.type == TYPE_WIN_UNC)
	{
		execResult = WIN_UNC_DRIVE_STUB.exec(this.path);

		if (!execResult)
		{
			throw new ParseError("Invalid path - " + this.path);
		}

		return execResult[0] + this.separator;
	}
	else if (this.type == TYPE_UNIX)
	{
		execResult = UNIX_VOLUME_NAME.exec(this.path);

		if (!execResult)
		{
			return "";
		}

		return execResult[0] + this.separator;
	}
}

AddMethod(constr, getVolumeRootFolder);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_public_method>
NAME <getVolumeRootFolder>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.ParseError
@classAbsolutePath.getVolumeRootFolder
>

TYPE

Code

var TYPE_WIN 		/*: int */ = 1;
var TYPE_WIN_UNC 	/*: int */ = 2;
var TYPE_UNIX 		/*: int */ = 3;

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_constants>
NAME <TYPE>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <

>

WIN

Code

var baseNameChar /*: String*/ = "[^\\|\\\\\\?\\*\\<\\\"\\:\\>\\+\\[\\]\\/]";
var extensionChar /*: String*/ = "[^\\|\\\\\\?\\*\\<\\\"\\:\\>\\+\\[\\]\\/\\.]";
var name /*: String*/ = "((" + baseNameChar + "+(\\." + extensionChar + "+))|(" + baseNameChar + "+(\\." + extensionChar + "+)?))";
var nameExtension /*: String*/ = "^((?P<BaseName>" + baseNameChar + "+?)(?P<HasExtension>\\.(?P<Extension>" + extensionChar + "+))?)$";
var driveLetter /*: String*/ = "(?P<DriveLetter>[a-zA-Z])";
var separator /*: String*/ = "(\\/|\\\\)"; 
var splitSeparator /*: String*/ = "\\/|\\\\"; 
var folderChain /*: String*/ = "(?P<FolderChain>(" + name + separator + ")*)"; 
var target /*: String */ = "(?P<TargetName>" + name + ")"; 
var path /*: String*/ = "^(?P<RootFolderPath>" + driveLetter + ":" + separator + ")(" + folderChain + target + "(?P<TerminatingSeparator>" + separator + ")?)?$";  
var driveStub /*: String*/ = "^" + driveLetter + ":";
var rootFolderStub /*: String*/ = driveStub + separator;
var drive /*: String*/ = driveStub + "$";
var rootFolder /*: String*/ = rootFolderStub + "$";

var WIN_PATH /*: Object*/ = RegExp_NamedCaptures(path);
var WIN_NAME /*: Object*/ = RegExp_NamedCaptures(nameExtension);
var WIN_SEPARATOR /*: RegExp*/ = new RegExp(splitSeparator);

var WIN_DRIVE /*: Object*/ = RegExp_NamedCaptures(drive);
var WIN_DRIVE_STUB /*: Object*/ = RegExp_NamedCaptures(driveStub);
var WIN_ROOTFOLDER /*: Object*/ = RegExp_NamedCaptures(rootFolder);
var WIN_ROOTFOLDER_STUB /*: Object*/ = RegExp_NamedCaptures(rootFolderStub);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_constants>
NAME <WIN>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@util.RegExp_NamedCaptures
>

WIN_UNC

Code

var baseNameChar /*: String*/ = "[^\\|\\\\\\?\\*\\<\\\"\\:\\>\\+\\[\\]\\/]";
var extensionChar /*: String*/ = "[^\\|\\\\\\?\\*\\<\\\"\\:\\>\\+\\[\\]\\/\\.]";
var name /*: String*/ = "((" + baseNameChar + "+(\\." + extensionChar + "+))|(" + baseNameChar + "+(\\." + extensionChar + "+)?))";
var nameExtension /*: String*/ = "^((?P<BaseName>" + baseNameChar + "+?)(?P<HasExtension>\\.(?P<Extension>" + extensionChar + "+))?)$";
var separator /*: String*/ = "(\\/|\\\\)"; 
var splitSeparator /*: String*/ = "\\/|\\\\"; 
var folderChain /*: String*/ = "(?P<FolderChain>(" + name + separator + ")*)"; 
var target /*: String */ = "(?P<TargetName>" + name +")"; 
var path /*: String*/ = "^(?P<RootFolderPath>" + separator + separator + "(?P<ServerName>" + name + ")" + separator + "(?P<ShareName>" + name + ")" + separator + ")(" + folderChain + target + "(?P<TerminatingSeparator>" + separator + ")?)?$";  

var driveStub /*: String*/ = "^" + separator + separator + "(?P<ServerName>" + name + ")" + separator + "(?P<ShareName>" + name + ")";
var rootFolderStub /*: String*/ = driveStub + separator;
var drive /*: String*/ = driveStub + "$";
var rootFolder /*: String*/ = rootFolderStub + "$";

var WIN_UNC_PATH /*: Object*/ = RegExp_NamedCaptures(path);
var WIN_UNC_NAME /*: Object*/ = RegExp_NamedCaptures(nameExtension);
var WIN_UNC_SEPARATOR /*: RegExp*/ = new RegExp(splitSeparator);

var WIN_UNC_DRIVE /*: Object*/ = RegExp_NamedCaptures(drive);
var WIN_UNC_DRIVE_STUB /*: Object*/ = RegExp_NamedCaptures(driveStub);
var WIN_UNC_ROOTFOLDER /*: Object*/ = RegExp_NamedCaptures(rootFolder);
var WIN_UNC_ROOTFOLDER_STUB /*: Object*/ = RegExp_NamedCaptures(rootFolderStub);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_constants>
NAME <WIN_UNC>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@util.RegExp_NamedCaptures
>

UNIX

Code

var baseNameChar /*: String*/ = "[^\\/]";
var extensionChar /*: String*/ = "[^\\/\\.]";
var name /*: String*/ = "((" + baseNameChar + "+(\\." + extensionChar + "+))|(" + baseNameChar + "+(\\." + extensionChar + "+)?))";
var nameExtension /*: String*/ = "^((?P<BaseName>" + baseNameChar + "+?)(?P<HasExtension>\\.(?P<Extension>" + extensionChar + "+))?)$";
var separator /*: String*/ = "\\/"; 
var splitSeparator /*: String*/ = "\\/"; 
var folderChain /*: String*/ = "(?P<FolderChain>(" + name + separator + ")*)"; 
var target /*: String */ = "(?P<TargetName>" + name + ")"; 
var path /*: String*/ = "^(?P<RootFolderPath>" + separator + ")(" + folderChain + target + "(?P<TerminatingSeparator>" + separator + ")?)?$";  

var rootFolderStub /*: String*/ = "^" + separator;
var rootFolder /*: String*/ = rootFolderStub + "$";

var volumeName /*: String*/ = "^" + separator + "(mnt|media|Media|Network|private\\/Network|net)" + separator + "(?P<VolumeName>" + name + ")";  

var UNIX_PATH /*: Object*/ = RegExp_NamedCaptures(path);
var UNIX_NAME /*: Object*/ = RegExp_NamedCaptures(nameExtension);
var UNIX_SEPARATOR /*: RegExp*/ = new RegExp(splitSeparator);

var UNIX_ROOTFOLDER /*: Object*/ = RegExp_NamedCaptures(rootFolder);
var UNIX_ROOTFOLDER_STUB /*: Object*/ = RegExp_NamedCaptures(rootFolderStub);

var UNIX_VOLUME_NAME /*: Object*/ = RegExp_NamedCaptures(volumeName);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_constants>
NAME <UNIX>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@util.RegExp_NamedCaptures
>

ParseError(description : String)

Code

function ParseError(
	description /*: String*/
)
{
	this.description = "ParseError : " + description;
	this.toString = function(){return this.description;}; 
}

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_struct>
NAME <ParseError>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@classAbsolutePath.ParseError
>

TypeError(description : String)

Code

function TypeError(
	description /*: String*/
)
{
	this.description = "TypeError : " + description;
	this.toString = function(){return this.description;}; 
}

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_struct>
NAME <TypeError>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@classAbsolutePath.TypeError
>

SeparatorError(description : String)

Code

function SeparatorError(
	description /*: String*/
)
{
	this.description = "SeparatorError : " + description;
	this.toString = function(){return this.description;}; 
}

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_struct>
NAME <SeparatorError>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@classAbsolutePath.SeparatorError
>

execName(name : String) : Array, throws TypeError

Code

function execName(
	name /*: String*/,
	type /*: int*/
) /*: Array, throws TypeError*/
{
	type = type || this.type;

	switch(type)
	{
		case TYPE_WIN:
			return WIN_NAME.exec(name);
			break;

		case TYPE_WIN_UNC:
			return WIN_UNC_NAME.exec(name);
			break;
				
		case TYPE_UNIX:
			return UNIX_NAME.exec(name);
			break;

		default:
			throw new TypeError("Unknown type number - " + type);
			break;
	}

	return false;
}

AddMethod(constr, execName);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_method>
NAME <execName>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.TypeError
@classAbsolutePath.execName
>

execPath(name : String [, type]) : Array, throws TypeError

Code

function execPath(
	path /*: String*/,
	type /*: int*/
) /*: Array, throws TypeError*/
{
	type = type || this.type;

	switch(type)
	{
		case TYPE_WIN:
			return WIN_PATH.exec(path);
			break;

		case TYPE_WIN_UNC:
			return WIN_UNC_PATH.exec(path);
			break;
				
		case TYPE_UNIX:
			return UNIX_PATH.exec(path);
			break;

		default:
			throw new TypeError("Unknown type number - " + type);
			break;
	}

	return null;
}

AddMethod(constr, execPath);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_private_method>
NAME <execPath>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
@core.AddMethod
@classAbsolutePath.TypeError
@classAbsolutePath.execPath
>

ExtendClass(constructor : Function, superConstructor : Function) : void

Code

function ExtendClass(
	constructor /*: Function*/,
	superConstructor /*: Function*/
) /*: void*/
{
	var f = function(){};
	f.prototype = superConstructor.prototype;

	var proto /*: Object*/ = constructor.prototype = new f();
	proto.prototype /*: Object*/ = proto;
	proto.superPrototype /*: Object*/ = f.prototype;
	proto.constructor /*: Function*/ = constructor;
	proto.superConstructor /*: Function*/ = superConstructor;

	constructor.superConstructor  = superConstructor;
}

Meta

<META>
MODULE <core>
INCLUDE <if_used>
TYPE <module_public_function>
NAME <ExtendClass>
CLASS <>
EXTENDS <>
REQUIRES <
>

AddMethod(constructor : Function, method : Function [, methodName : String]) : void

Code

function AddMethod(
	constructor /*: Function*/,
	method /* Function*/,
	methodName /*: Function*/
) /*: void*/
{
	var methodName /*: String*/ = methodName || Function_GetIdentifier(method);
	var proto /*: Object*/ = constructor.prototype;
	
	method.name = methodName;
	method.ownerProto = proto;
	proto[methodName] = method;
}

Meta

<META>
MODULE <core>
INCLUDE <if_used>
TYPE <module_public_function>
NAME <AddMethod>
CLASS <>
EXTENDS <>
REQUIRES <
@core.Function_GetIdentifier
>

Function_GetIdentifier(f : Function) : String

Code

function Function_GetIdentifier(f /*: Function*/) /*: String*/
{
	var execResult /*: Array*/ = /^\s*function\s*(\w+)/.exec(f.toString());

	return execResult ? execResult[1] : "anonymous";
}

Meta

<META>
MODULE <core>
INCLUDE <if_used>
TYPE <module_public_function>
NAME <Function_GetIdentifier>
CLASS <>
EXTENDS <>
REQUIRES <
>

String_Trim(s : String) : String

Code

function String_Trim(
	s /*: String*/
) /*: String*/
{
	return s.replace(/^\s\s*|\s*\s$/g, "");
}

Meta

<META>
MODULE <util>
INCLUDE <if_used>
TYPE <module_public_function>
NAME <String_Trim>
CLASS <>
EXTENDS <>
REQUIRES <
>

String_LastChar(s : String) : String

Code

function String_LastChar(
	s /*: String*/,
	n /*: int*/
) /*: String*/
{
	return s.charAt(s.length - (n || 1));
}

Meta

<META>
MODULE <util>
INCLUDE <if_used>
TYPE <module_public_function>
NAME <String_LastChar>
CLASS <>
EXTENDS <>
REQUIRES <
>

String_RemoveLastChar(s : String) : String

Code

function String_RemoveLastChar(
	s /*: String*/,
	n /*: int*/
) /*: String*/
{
	return s.substring(0, s.length - (n || 1));
}

Meta

<META>
MODULE <util>
INCLUDE <if_used>
TYPE <module_public_function>
NAME <String_RemoveLastChar>
CLASS <>
EXTENDS <>
REQUIRES <
>

RegExp_NamedCaptures(pattern : String) : Object

Code

function RegExp_NamedCaptures(
	pattern /*: String*/, 
	global /*: Boolean*/
) /*: Object*/
{
	var leftNameMarker = ("\\" + ("?P<").split("").join("\\")).replace(/^\\$/g, "");
	var rightNameMarker =  ("\\" + (">").split("").join("\\")).replace(/^\\$/g, "");

	/* RegExps */
	var nameRegExp /*: RegExp*/ = new RegExp("\\(" + leftNameMarker + "(\\w+)" + rightNameMarker, "g");

	//alert(String(nameRegExp));
	var parenRegExp /*: RegExp*/ = /(\\*)\(/g;
	
	/* Init RegExps */
	nameRegExp.lastIndex = 0;
	parenRegExp.lastIndex = 0;

	/* Loop */
	var execResult /*: Array*/ = [];
	var name /*: String*/ = "";
	var names /*: Object*/ = {};
	var nameIndex /*: int*/ = 0;
	var parenCount /*: int*/ = 0;
	var isCapturing /*: Boolean*/;

	while(execResult = nameRegExp.exec(pattern))
	{
		name = execResult[1];
		nameIndex = execResult.index;
			
		isCapturing = false;
		
		while(execResult = parenRegExp.exec(pattern))
		{
			isCapturing = !((execResult[1].length) % 2);

			if (parenRegExp.lastIndex - 1 <= nameIndex) 
			{
				parenCount += isCapturing ? 1 : 0;
			}

			if (parenRegExp.lastIndex - 1 >= nameIndex) 
			{
				break;
			}
		}

		parenRegExp.lastIndex = nameIndex + 1;

		if (isCapturing)
		{
			names[name] = parenCount;
		}
	}	

	var cleanPattern /*: String*/ = pattern.replace(nameRegExp, "(");

	//alert(cleanPattern);

	/* Object */

	var f = function(){};

	f.prototype.re = new RegExp(cleanPattern, global ? "g" : "");
	
	f.prototype.exec = function (s /*: String*/) /*: Array.<String>*/ {

		this.re.lastIndex = 0;
		var execResult /*: Array.<String>*/ = this.re.exec(s);
		
		if (!execResult) {
			return null;
		}

		for (var k /*: String*/ in names) {
			execResult[k] = execResult[names[k]];
		}

		return execResult;
	}

	f.prototype.test = function (s /*: String*/) /*: Boolean*/
	{
		this.re.lastIndex = 0;
		return this.re.test(s);
	}

	return new f();
}

Meta

<META>
MODULE <util>
INCLUDE <if_used>
TYPE <module_public_function>
NAME <RegExp_NamedCaptures>
CLASS <>
EXTENDS <>
REQUIRES <
>

classAbsolutePath - END

Code

return constr;

})();

//makePublic(classAbsolutePath);

Meta

<META>
MODULE <io>
INCLUDE <if_class_used>
TYPE <module_class_end>
NAME <classAbsolutePath - END>
CLASS <classAbsolutePath>
EXTENDS <classBase>
REQUIRES <
>