Subversion Repositories wimsdev

Rev

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

  1. /*
  2.         DynAPI Distribution
  3.         dynapi.functions.String extension      
  4. */
  5.  
  6. var f = dynapi.functions;
  7. f.String = {}; // used by dynapi.library
  8.  
  9.  
  10. // String Functions --------------------------------
  11.  
  12. f.trim = function(s,dir){
  13.         if(!s) return;
  14.         else s+=''; // make sure s is a string
  15.         dir=(dir)? dir:'<>';
  16.         if(dir=='<'||dir=='<>') s=s.replace(/^(\s+)/g,'');
  17.         if(dir=='>'||dir=='<>') s=s.replace(/(\s+)$/g,'');
  18.         return s;
  19.        
  20. };
  21. f.strRepeat = function(s,n) {
  22.         if(!s) return '';
  23.         var i,a=[];
  24.         for(i=1;i<=n;i++){
  25.                 a[a.length]=s;
  26.         }
  27.         return a.join('');
  28. };
  29. f.strReverse = function(s) {
  30.         if(!s) return '';
  31.         var a=(s+'').split('');
  32.         a.reverse();
  33.         return a.join('');
  34. };
  35. f.strStuff = function(s,v,index) {
  36.         if(!s) return '';      
  37.         if (index==null) s=s+v+'';
  38.         else {
  39.                 var t1=t2=s+'';
  40.                 s=t1.substr(0,index)+v+t2.substr(index,t2.length-index);
  41.         }
  42.         return s;
  43. };
  44.