Moving type conversion in its own file and adding

Added buffer object to carry functions and comments
related to oe buffer
This commit is contained in:
2014-11-01 16:57:21 +01:00
parent 5a37474988
commit 5c94d528fd
3 changed files with 207 additions and 49 deletions

80
lib/types.js Normal file
View File

@@ -0,0 +1,80 @@
/**
* @function color
* Convert a color to message string
* @param {string|number} value Color to convert
* @return {string} Converted color
*/
function color (value) {
"use strict";
return value ? value : "none";
}
/**
* @function bool
* Convert a boolean value to message string
* @param {bool} value Boolean to convert
* @return {string} Converted boolean
*/
function bool (value) {
"use strict";
return value ? "T" : "F";
}
/**
* @function position
* Convert a position to message string
* @param {number} line Line of position starting with 1
* @param {number} col Column of position starting with 0
* @return {string} Converted position
*/
function position (line, col) {
"use strict";
return line+"/"+col;
}
/**
* @function string
* Convert a string to message string
* @param {string} value String to convert
* @return {string} Converted string
*/
function string (value) {
"use strict";
var buffer = "\"";
for (var i = 0 ; i < value.length ; ++i){
switch (value[i]) {
case "\n" :
buffer += "\\n";
break;
case "\t" :
buffer += "\\t";
break;
case "\r" :
buffer += "\\r";
break;
case "\\" :
buffer += "\\\\";
break;
case "\"" :
buffer += "\\\"";
break;
default :
buffer += value[i];
break;
}
}
buffer += "\"";
return buffer;
}
module.exports.string = string;
module.esports.color = color;
module.exports.position = position;
module.exports.bool = bool;