/**
* File name Processing
* @param filename
* @return
*/
function _filename (filename)
{
if (!this.file_exists (this.root+filename))
{
This.halt ("Filename:file" +filename+ "does not exist.");
}
return this.root+filename;
}
/**
* Variable name processing
* @param varname
* @return
*/
function _varname (varname)
{
Return "{" +varname+ "}";
}
/**
* Complete the processing of the string
* @param str
* @return
*/
function _finish (str)
{
var re=new RegExp ("{[^ \\t\\r\\n\\}]+\\}", "G");
if (this.unknowns== "remove")
{
Str=str.replace (Re, "");
}
else if (this.unknowns== "comment")
{
Str=str.replace (Re, "<!--Template Variable undefined-->");
}
Else
{
}
return str;
}
function _halt (msg)
{
this.last_error=msg;
if (this.halt_on_error!= "no")
{
_haltmsg (msg);
}
if (this.halt_on_error== "yes")
{
Alert ("halted.");
System.exit (0);
}
}
function _haltmsg (msg)
{
Alert ("Template Error:" +msg);
}
/**
* HashMap Constructor
*/
function HashMap ()
{
this.length = 0;
This.prefix = "hashmap_prefix_20050524_";
}
/**
* Add key value pairs to HashMap
*/
HashMap.prototype.put = function (key, value)
{
This[this.prefix + key] = value;
This.length + +;
}
/**
* Get value from HashMap
*/
HashMap.prototype.get = function (key)
{
Return typeof This[this.prefix + key] = = "undefined"
? Null:this[this.prefix + key];
}
/**
* Get a collection of all keys from the HashMap, return as an array
*/
HashMap.prototype.keySet = function ()
{
var arrkeyset = new Array ();
var index = 0;
for (Var strkey in this)
{
if (strkey.substring (0,this.prefix.length) = = This.prefix)
Arrkeyset[index + +] = strkey.substring (this.prefix.length);
}
return arrkeyset.length = = 0? Null:arrkeyset;
}
/**
* Gets the collection of value from the HashMap and returns it as an array
*/
HashMap.prototype.values = function ()
{
var arrvalues = new Array ();
var index = 0;
for (Var strkey in this)
{
if (strkey.substring (0,this.prefix.length) = = This.prefix)
Arrvalues[index + +] = This[strkey];
}
return arrvalues.length = = 0? Null:arrvalues;
}
/**
* Get the number of value values for HashMap
*/
HashMap.prototype.size = function ()
{
return this.length;
}
/**
* Delete the specified value
*/
HashMap.prototype.remove = function (key)
{
Delete This[this.prefix + key];
This.length--;
}
/**
* Empty HashMap
*/
HashMap.prototype.clear = function ()
{
for (Var strkey in this)
{
if (strkey.substring (0,this.prefix.length) = = This.prefix)
Delete This[strkey];
}
this.length = 0;
}
/**
* Determine if the HashMap is empty
*/
HashMap.prototype.isEmpty = function ()
{
return this.length = = 0;
}
/**
* Determine if a key exists in HashMap
*/
HashMap.prototype.containsKey = function (key)
{
for (Var strkey in this)
{
if (strkey = = This.prefix + key)
return true;
}
return false;
}
/**
* Determine if there is a value in HashMap
*/
HashMap.prototype.containsValue = function (value)
{
for (Var strkey in this)
{
if (this[strkey] = = value)
return true;
}
return false;
}
/**
* Add a HashMap value to another hashmap, the argument must be HashMap
*/
HashMap.prototype.putAll = function (map)
{
if (map = = null)
Return
if (Map.constructor!= jhashmap)
Return
var arrkey = Map.keyset ();
var arrvalue = Map.values ();
for (var i in Arrkey)
This.put (Arrkey[i],arrvalue[i]);
}
Tostring
HashMap.prototype.toString = function ()
{
var str = "";
for (Var strkey in this)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service