Advertisement
IWBH_01

DataView.prototype.getString (browser javascript) (isfast?)

Aug 30th, 2021 (edited)
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* //this version of getString doesn't work right
  2. DataView.prototype.getString=function(bi,L){
  3.  var c,ps="",i=0,e=L%4,x="\\x",z="0"; L-=e;
  4.  while(i!=L){
  5.   c=this.getUint32(bi+i).toString(16);
  6.   ps+=x+c[0]+(c[1]||z)+x+(c[2]||z)+(c[3]||z)+x+(c[4]||z)+(c[5]||z)+x+(c[6]||z)+(c[7]||z);
  7.   i+=4;
  8.  }
  9.  while(e--){ ps+=x+this.getUint8(bi+i).toString(16);
  10.   i++;
  11.  }
  12.  return eval('"'+ps+'"');
  13. };
  14. */
  15.  
  16. //good version:
  17. DataView.prototype.getString=function(bi,L){
  18.  var i=0,s="";
  19.  while(i!=L){
  20.   s+=String.fromCharCode(this.getUint8(bi+i));
  21.   i++;
  22.  }
  23.  return s;
  24. };
  25.  
  26.  
  27. DataView.prototype.setString=function(bi,s){
  28.  var i=0,L=s.length;
  29.  while(i!=L){
  30.   this.setUint8(bi+i,s.charCodeAt(i));
  31.   i++;
  32.  }
  33. };
  34.  
  35.  
  36.  
  37. self.strNui8=function strNui8(s,ui8,u8i){
  38.  var L=s.length,i=L; u8i=u8i||0;
  39.   while(i--) ui8[u8i+i]=s.charCodeAt(i);
  40. };
  41.  
  42.  
  43. self.ui8Gstr=function Ui8Gstr(ui8,i,L){
  44.  var s="";
  45.   while(i!=L){ s+=String.fromCharCode(ui8[i]); i++; }
  46.   return s;
  47. };
  48.  
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement