var Character = function(character){ // 单个字符类
if (character.length != 1){
throw Error("[Error:Arguments error.\nclass:org.xianyun.Character]");
}
this.value = character; // private:
this.charCode = character.charCodeAt(0); // public:readonly.
};
Character.reverseCase = function(character){ // 单个字符大小写反转,静态方法。
var charCode = character.charCodeAt(0);
if (charCode>=65 && charCode<=90){ // A-Z
return String.fromCharCode(charCode + 32);
}else if(charCode>=97 && charCode<=122){ // a-z
return String.fromCharCode(charCode - 32);
}else {
return character;
}
};
Character.prototype.reverseCase = function(){ // 单个字符大小写反转,成员方法。
return Character.reverseCase(this.value);
};
String.prototype.reverse = function(){ // 字符串顺序反转。
var s = "";
for (var i=this.length-1; i>=0; i--){
s += this.charAt(i);
}
return s;
};String.prototype.reverseCase = function(){ // 字符串大小写反转
var s = "";
for (var i=0; i<this.length; i++){
s += Character.reverseCase(this.charAt(i));
//s += new Character(this.charAt(i)).reverseCase();
}
return s;
};