Subversion Repositories HomeAutomation

Rev

Rev 1644 | Rev 1647 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. function array_length(array)
  3. {
  4.     var count = 0;
  5.    
  6.     for (var n in array)
  7.     {
  8.         count++;
  9.     }
  10.    
  11.     return count;
  12. }
  13.  
  14. function in_array(array, item)
  15. {
  16.     for (var n in array)
  17.     {
  18.         if (array[n] == item)
  19.         {
  20.             return true;
  21.         }
  22.     }
  23.    
  24.     return false;
  25. }
  26.  
  27. function key_in_array(array, key)
  28. {
  29.     for (var n in array)
  30.     {
  31.         if (n == key)
  32.         {
  33.             return true;
  34.         }
  35.     }
  36.    
  37.     return false;
  38. }
  39.  
  40. String.prototype.ltrim = function(charlist)
  41. {
  42.     charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
  43.     var re = new RegExp('^[' + charlist + ']+', 'g');
  44.     return this.replace(re, '');
  45. }
  46.  
  47. String.prototype.rtrim = function(charlist)
  48. {
  49.     charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');
  50.     var re = new RegExp('[' + charlist + ']+$', 'g');
  51.     return this.replace(re, '');
  52. }
  53.  
  54. String.prototype.trim = function(charlist)
  55. {
  56.     var str = this.ltrim(charlist);
  57.     return str.rtrim(charlist);
  58. }
  59.