1 28 package org.eclipse.swt.internal.mozilla; 29 30 public class nsString { 31 private int handle; 32 33 public nsString() { 34 handle = XPCOM.nsString_new(); 35 } 36 37 public nsString(String string) { 38 if (string != null) { 39 char[] aString = new char[string.length() + 1]; 40 string.getChars(0, string.length(), aString, 0); 41 handle = XPCOM.nsString_new(aString); 42 } 43 } 44 45 public int getAddress() { 46 return handle; 47 } 48 49 public String toString() { 50 if (handle == 0) return null; 51 int length = XPCOM.nsString_Length(handle); 52 int buffer = XPCOM.nsString_get(handle); 53 char[] dest = new char[length]; 54 XPCOM.memmove(dest, buffer, length * 2); 55 return new String (dest); 56 } 57 58 public void dispose() { 59 if (handle == 0) return; 60 XPCOM.nsString_delete(handle); 61 handle = 0; 62 } 63 } | Popular Tags |