1 var LSdebug_active = 0;
3 function LSdebug(arguments) {
4 if (LSdebug_active != 1) return;
5 if (typeof console != 'undefined') {
6 console.log(arguments);
9 if (typeof opera != 'undefined') {
10 opera.postError(arguments);
17 * Construction of formatted string
19 * This function returns a formatted string according to given data & format parameters
21 * @author Benjamin Renard <brenard@easter-eggs.com>
23 * @param[in] $format string String Format
24 * @param[in] $data mixed Data used to compose the string.
25 * It can be strings array or object.
26 * @param[in] $meth string Object method name to call to get the new value for the formatted string.
28 * Invocation example :
29 * getFData('%{test1} je %{test2}',{
30 * getValue: function(val) {
39 * @retval string The formatted string
41 function getFData(format,data,meth) {
42 var getMotif = new RegExp('%\{(([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9])+)?)\}');
45 if(($type(data)=='object') || ($type(data)=='array')) {
46 if ($type(data[meth])!='function') {
48 var ch = getMotif.exec(format);
59 var val=data[ch[2]].substr(s,l);
64 format=format.replace(new RegExp('%\{'+ch[1]+'\}'),val);
73 var ch = getMotif.exec(format);
76 val=data[meth](ch[2]);
79 LSdebug('getFData() : '+meth+'() -> rater');
83 if($type(ch[4])&&ch[4]!="") {
84 if ($type(ch[6])&&ch[6]!="") {
95 format=format.replace(new RegExp('%\{'+ch[1]+'\}'),val);
107 * Delete accentuated characters in a string
109 * @param[in] $string Original string
111 * @retval string de-accentuated string
113 function replaceAccents(str) {
114 var new_str = String(str);
116 new Array("à","á","â","ã","ä","ç","è","é","ê","ë","ì","í","î","ï","ñ","ò","ó","ô","õ","ö","ù","ú","û","ü","ý","ÿ","À","Á","Â","Ã","Ä","Ç","È","É","Ê","Ë","Ì","Í","Î","Ï","Ñ","Ò","Ó","Ô","Õ","Ö","Ù","Ú","Û","Ü","Ý");
118 new Array("a","a","a","a","a","c","e","e","e","e","i","i","i","i","n","o","o","o","o","o","u","u","u","u","y","y","A","A","A","A","A","C","E","E","E","E","I","I","I","I","N","O","O","O","O","O","U","U","U","U","Y");
119 if (str && str!= "") {
120 for (i=0; i<accent.length; i++) {
121 var reg_exp= RegExp(accent[i], "gi");
122 new_str = new_str.replace (reg_exp, sans_accent[i]);
129 * Replace spaces or tabs of a string by an argument
131 * @param[in] $string The original string
132 * @param[in] $string The character to set instead of spaces or tabs
134 * @retval string The modified outspaced string
136 function replaceSpaces(str,to) {
140 var new_str = String(str);
141 if (str && str!= "") {
142 var reg_exp= RegExp('[ \t]', "gi");
143 new_str = new_str.replace (reg_exp, to);
149 * Add one variable with value in URL
150 * @param[in] url string The original URL
151 * @param[in] name string The variable name
152 * @param[in] value string The value of the variable
154 * @retval string The URL with the value
156 function urlAddVar(url,name,value) {
158 var isExtended = RegExp('[?]');
159 if (isExtended.test(url)) {
165 return url + name + '=' + value;