Files
vim-netbeans-server/lib/types.js
boudin 5c94d528fd Moving type conversion in its own file and adding
Added buffer object to carry functions and comments
related to oe buffer
2014-11-01 16:57:21 +01:00

81 lines
1.7 KiB
JavaScript

/**
* @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;