home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / RichText / UnicodeBuffer.class (.txt) < prev   
Encoding:
Java Class File  |  1998-01-08  |  1.4 KB  |  48 lines

  1. package icontrols.RichText;
  2.  
  3. import com.ms.dll.DllLib;
  4.  
  5. class UnicodeBuffer extends CharBuffer {
  6.    char[] buffer;
  7.    int offset;
  8.  
  9.    int allocCoTaskMem() {
  10.       int result = DllLib.allocCoTaskMem(this.buffer.length * 2);
  11.       DllLib.copy(this.buffer, 0, result, this.buffer.length);
  12.       return result;
  13.    }
  14.  
  15.    void putCoTaskMem(int ptr) {
  16.       DllLib.copy(ptr, this.buffer, 0, this.buffer.length);
  17.       this.offset = 0;
  18.    }
  19.  
  20.    UnicodeBuffer(int size) {
  21.       this.buffer = new char[size];
  22.    }
  23.  
  24.    public String getString() {
  25.       int i;
  26.       for(i = this.offset; i < this.buffer.length && this.buffer[i] != 0; ++i) {
  27.       }
  28.  
  29.       String result = new String(this.buffer, this.offset, i - this.offset);
  30.       if (i < this.buffer.length) {
  31.          ++i;
  32.       }
  33.  
  34.       this.offset = i;
  35.       return result;
  36.    }
  37.  
  38.    public void putString(String s) {
  39.       int count = Math.min(s.length(), this.buffer.length - this.offset);
  40.       s.getChars(0, count, this.buffer, this.offset);
  41.       this.offset += count;
  42.       if (this.offset < this.buffer.length) {
  43.          this.buffer[this.offset++] = 0;
  44.       }
  45.  
  46.    }
  47. }
  48.