comparison dwt/dnd/FileTransfer.d @ 268:5995c228c72f

Fix: string termination
author Frank Benoit <benoit@tionex.de>
date Sun, 06 Jul 2008 15:35:58 +0200
parents c0d810de7093
children
comparison
equal deleted inserted replaced
267:6383fb4cdfc3 268:5995c228c72f
64 /** 64 /**
65 * This implementation of <code>javaToNative</code> converts a list of file names 65 * This implementation of <code>javaToNative</code> converts a list of file names
66 * represented by a java <code>String[]</code> to a platform specific representation. 66 * represented by a java <code>String[]</code> to a platform specific representation.
67 * Each <code>String</code> in the array contains the absolute path for a single 67 * Each <code>String</code> in the array contains the absolute path for a single
68 * file or directory. 68 * file or directory.
69 * 69 *
70 * @param object a java <code>String[]</code> containing the file names to be converted 70 * @param object a java <code>String[]</code> containing the file names to be converted
71 * @param transferData an empty <code>TransferData</code> object that will 71 * @param transferData an empty <code>TransferData</code> object that will
72 * be filled in on return with the platform specific format of the data 72 * be filled in on return with the platform specific format of the data
73 * 73 *
74 * @see Transfer#nativeToJava 74 * @see Transfer#nativeToJava
75 */ 75 */
76 public override void javaToNative(Object object, TransferData transferData) { 76 public override void javaToNative(Object object, TransferData transferData) {
77 transferData.result = 0; 77 transferData.result = 0;
78 if (!checkFile(object) || !isSupportedType(transferData)) { 78 if (!checkFile(object) || !isSupportedType(transferData)) {
119 * Each String in the array contains the absolute path for a single file or directory. 119 * Each String in the array contains the absolute path for a single file or directory.
120 * 120 *
121 * @param transferData the platform specific representation of the data to be converted 121 * @param transferData the platform specific representation of the data to be converted
122 * @return a java <code>String[]</code> containing a list of file names if the conversion 122 * @return a java <code>String[]</code> containing a list of file names if the conversion
123 * was successful; otherwise null 123 * was successful; otherwise null
124 * 124 *
125 * @see Transfer#javaToNative 125 * @see Transfer#javaToNative
126 */ 126 */
127 public override Object nativeToJava(TransferData transferData) { 127 public override Object nativeToJava(TransferData transferData) {
128 if ( !isSupportedType(transferData) || transferData.pValue is null || transferData.length <= 0 ) return null; 128 if ( !isSupportedType(transferData) || transferData.pValue is null || transferData.length <= 0 ) return null;
129 String temp = transferData.pValue[ 0 .. transferData.length ]; 129 String temp = transferData.pValue[ 0 .. transferData.length ];
131 int offset = 0; 131 int offset = 0;
132 for (int i = 0; i < temp.length - 1; i++) { 132 for (int i = 0; i < temp.length - 1; i++) {
133 if (temp[i] is '\r' && temp[i+1] is '\n') { 133 if (temp[i] is '\r' && temp[i+1] is '\n') {
134 int size = i - offset; 134 int size = i - offset;
135 char* file = cast(char*)OS.g_malloc(size + 1); 135 char* file = cast(char*)OS.g_malloc(size + 1);
136 String fileBuffer = new char[size + 1]; 136 file[ 0 .. size ] = temp[ offset .. offset+size ];
137 System.arraycopy(temp, offset, fileBuffer, 0, size); 137 file[ size ] = '\0';
138 file[ 0 .. size + 1 ] = fileBuffer; 138 files ~= file;
139 char*[] newFiles = new char*[files.length + 1];
140 SimpleType!(char*).arraycopy(files, 0, newFiles, 0, files.length);
141 newFiles[files.length] = file;
142 files = newFiles;
143 offset = i + 2; 139 offset = i + 2;
144 } 140 }
145 } 141 }
146 if (offset < temp.length - 2) { 142 if (offset < temp.length - 2) {
147 int size = temp.length - offset; 143 int size = temp.length - offset;
148 char* file = cast(char*)OS.g_malloc(size + 1); 144 char* file = cast(char*)OS.g_malloc(size + 1);
149 String fileBuffer = new char[size + 1]; 145 file[ 0 .. size ] = temp[ offset .. offset+size ];
150 System.arraycopy(temp, offset, fileBuffer, 0, size); 146 file[ size ] = '\0';
151 file[ 0 .. size+1 ] = fileBuffer; 147 files ~= file;
152 char*[] newFiles = new char*[files.length + 1];
153 SimpleType!(char*).arraycopy(files, 0, newFiles, 0, files.length);
154 newFiles[files.length] = file;
155 files = newFiles;
156 } 148 }
157 String[] fileNames; 149 String[] fileNames;
158 for (int i = 0; i < files.length; i++) { 150 for (int i = 0; i < files.length; i++) {
159 GError* error; 151 GError* error;
160 auto localePtr = OS.g_filename_from_uri(files[i], null, &error); 152 auto localePtr = OS.g_filename_from_uri(files[i], null, &error);