Mercurial > projects > dwt-mac
comparison dwt/internal/Compatibility.d @ 126:38807a925e24
Fixed compile errors, support for SWT language files
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Fri, 16 Jan 2009 23:35:40 +0100 |
parents | d8635bb48c7c |
children | 3d4579727e0e |
comparison
equal
deleted
inserted
replaced
125:5583f8eeee6c | 126:38807a925e24 |
---|---|
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.eclipse.org/legal/epl-v10.html | 6 * http://www.eclipse.org/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * IBM Corporation - initial API and implementation | 9 * IBM Corporation - initial API and implementation |
10 * | |
11 * Port to the D programming language: | 10 * Port to the D programming language: |
12 * Frank Benoit <benoit@tionex.de> | 11 * Frank Benoit <benoit@tionex.de> |
13 * Jacob Carlborg <jacob.carlborg@gmail.com> | |
14 *******************************************************************************/ | 12 *******************************************************************************/ |
15 module dwt.internal.Compatibility; | 13 module dwt.internal.Compatibility; |
16 | 14 |
17 import tango.sys.Process; | 15 import dwt.dwthelper.utils; |
16 /+ | |
17 import java.io.File; | |
18 import java.text.MessageFormat; | |
19 import java.util.MissingResourceException; | |
20 import java.util.ResourceBundle; | |
21 import java.util.zip.DeflaterOutputStream; | |
22 import java.util.zip.InflaterInputStream; | |
23 +/ | |
18 | 24 |
19 import dwt.DWT; | 25 import dwt.DWT; |
20 import dwt.dwthelper.BufferedInputStream; | |
21 public import dwt.dwthelper.FileInputStream; | 26 public import dwt.dwthelper.FileInputStream; |
22 public import dwt.dwthelper.FileOutputStream; | 27 public import dwt.dwthelper.FileOutputStream; |
23 public import dwt.dwthelper.InflaterInputStream; | 28 public import dwt.dwthelper.InflaterInputStream; |
29 import dwt.dwthelper.BufferedInputStream; | |
24 import dwt.dwthelper.ResourceBundle; | 30 import dwt.dwthelper.ResourceBundle; |
25 import dwt.dwthelper.utils; | 31 |
26 | 32 import Math = tango.math.Math; |
27 /+ | 33 import Unicode = tango.text.Unicode; |
28 import java.io.File; | 34 import tango.sys.Process; |
29 import java.text.MessageFormat; | 35 import tango.text.convert.Format; |
30 import java.util.zip.DeflaterOutputStream; | |
31 import java.util.zip.InflaterInputStream; | |
32 +/ | |
33 | 36 |
34 /** | 37 /** |
35 * This class is a placeholder for utility methods commonly | 38 * This class is a placeholder for utility methods commonly |
36 * used on J2SE platforms but not supported on some J2ME | 39 * used on J2SE platforms but not supported on some J2ME |
37 * profiles. | 40 * profiles. |
224 * | 227 * |
225 * @param c the character | 228 * @param c the character |
226 * @return true when the character is a letter | 229 * @return true when the character is a letter |
227 */ | 230 */ |
228 public static bool isLetter(dchar c) { | 231 public static bool isLetter(dchar c) { |
229 return Character.isLetter(c); | 232 return Unicode.isLetter(c); |
230 } | 233 } |
231 | 234 |
232 /** | 235 /** |
233 * Answers whether the character is a letter or a digit. | 236 * Answers whether the character is a letter or a digit. |
234 * | 237 * |
235 * @param c the character | 238 * @param c the character |
236 * @return true when the character is a letter or a digit | 239 * @return true when the character is a letter or a digit |
237 */ | 240 */ |
238 public static bool isLetterOrDigit(dchar c) { | 241 public static bool isLetterOrDigit(dchar c) { |
239 return Character.isLetterOrDigit(c); | 242 return Unicode.isLetterOrDigit(c); |
240 } | 243 } |
241 | 244 |
242 /** | 245 /** |
243 * Answers whether the character is a Unicode space character. | 246 * Answers whether the character is a Unicode space character. |
244 * | 247 * |
245 * @param c the character | 248 * @param c the character |
246 * @return true when the character is a Unicode space character | 249 * @return true when the character is a Unicode space character |
247 */ | 250 */ |
248 public static bool isSpaceChar(dchar c) { | 251 public static bool isSpaceChar(dchar c) { |
249 return Character.isSpaceChar(c); | 252 return Unicode.isSpace(c); |
250 } | 253 } |
251 | 254 |
252 /** | 255 /** |
253 * Answers whether the character is a whitespace character. | 256 * Answers whether the character is a whitespace character. |
254 * | 257 * |
255 * @param c the character to test | 258 * @param c the character to test |
256 * @return true if the character is whitespace | 259 * @return true if the character is whitespace |
257 */ | 260 */ |
258 public static bool isWhitespace(dchar c) { | 261 public static bool isWhitespace(dchar c) { |
259 return Character.isWhitespace(c); | 262 return Unicode.isWhitespace(c); |
260 } | 263 } |
261 | 264 |
262 /** | 265 /** |
263 * Execute a program in a separate platform process if the | 266 * Execute a program in a separate platform process if the |
264 * underlying platform support this. | 267 * underlying platform support this. |
291 public static void exec(String[] progArray) { | 294 public static void exec(String[] progArray) { |
292 auto proc = new Process( progArray ); | 295 auto proc = new Process( progArray ); |
293 proc.execute; | 296 proc.execute; |
294 } | 297 } |
295 | 298 |
299 const ImportData[] SWTMessagesBundleData = [ | |
300 getImportData!( "swt.internal.SWTMessages.properties" ), | |
301 getImportData!( "swt.internal.SWTMessages_ar.properties" ), | |
302 getImportData!( "swt.internal.SWTMessages_cs.properties" ), | |
303 getImportData!( "swt.internal.SWTMessages_da.properties" ), | |
304 getImportData!( "swt.internal.SWTMessages_de.properties" ), | |
305 getImportData!( "swt.internal.SWTMessages_el.properties" ), | |
306 getImportData!( "swt.internal.SWTMessages_es.properties" ), | |
307 getImportData!( "swt.internal.SWTMessages_fi.properties" ), | |
308 getImportData!( "swt.internal.SWTMessages_fr.properties" ), | |
309 getImportData!( "swt.internal.SWTMessages_hu.properties" ), | |
310 getImportData!( "swt.internal.SWTMessages_it.properties" ), | |
311 getImportData!( "swt.internal.SWTMessages_iw.properties" ), | |
312 getImportData!( "swt.internal.SWTMessages_ja.properties" ), | |
313 getImportData!( "swt.internal.SWTMessages_ko.properties" ), | |
314 getImportData!( "swt.internal.SWTMessages_nl.properties" ), | |
315 getImportData!( "swt.internal.SWTMessages_no.properties" ), | |
316 getImportData!( "swt.internal.SWTMessages_pl.properties" ), | |
317 getImportData!( "swt.internal.SWTMessages_pt_BR.properties" ), | |
318 getImportData!( "swt.internal.SWTMessages_pt.properties" ), | |
319 getImportData!( "swt.internal.SWTMessages_ru.properties" ), | |
320 getImportData!( "swt.internal.SWTMessages_sv.properties" ), | |
321 getImportData!( "swt.internal.SWTMessages_tr.properties" ), | |
322 getImportData!( "swt.internal.SWTMessages_zh_HK.properties" ), | |
323 getImportData!( "swt.internal.SWTMessages_zh.properties" ), | |
324 getImportData!( "swt.internal.SWTMessages_zh_TW.properties" ) | |
325 ]; | |
326 | |
296 private static ResourceBundle msgs = null; | 327 private static ResourceBundle msgs = null; |
297 | 328 |
298 /** | 329 /** |
299 * Returns the NLS'ed message for the given argument. This is only being | 330 * Returns the NLS'ed message for the given argument. This is only being |
300 * called from DWT. | 331 * called from DWT. |
305 * @see DWT#getMessage(String) | 336 * @see DWT#getMessage(String) |
306 */ | 337 */ |
307 public static String getMessage(String key) { | 338 public static String getMessage(String key) { |
308 String answer = key; | 339 String answer = key; |
309 | 340 |
310 /*if (key is null) { | 341 if (key is null) { |
311 DWT.error (DWT.ERROR_NULL_ARGUMENT); | 342 DWT.error (DWT.ERROR_NULL_ARGUMENT); |
312 }*/ | 343 } |
313 if (msgs is null) { | 344 if (msgs is null) { |
314 try { | 345 try { |
315 msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ | 346 msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$ |
316 } catch (IOException ex) { | 347 } catch (MissingResourceException ex) { |
317 answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ | 348 answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ |
318 } | 349 } |
319 } | 350 } |
320 if (msgs !is null) { | 351 if (msgs !is null) { |
321 try { | 352 try { |
322 answer = msgs.getString(key); | 353 answer = msgs.getString(key); |
323 } catch (MissingResourceException ex2) {} | 354 } catch (MissingResourceException ex2) {} |
324 } | 355 } |
325 return answer; | 356 return answer; |
326 } | 357 } |
327 /++ PORTING_LEFT | 358 |
328 public static String getMessage(String key, Object[] args) { | 359 public static String getMessage(String key, Object[] args) { |
329 String answer = key; | 360 String answer = key; |
330 | 361 |
331 if (/*key == null ||*/ args is null) { | 362 if (key is null || args is null) { |
332 DWT.error (DWT.ERROR_NULL_ARGUMENT); | 363 DWT.error (DWT.ERROR_NULL_ARGUMENT); |
333 } | 364 } |
334 if (msgs is null) { | 365 if (msgs is null) { |
335 try { | 366 try { |
336 msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$ | 367 msgs = ResourceBundle.getBundle(SWTMessagesBundleData); //$NON-NLS-1$ |
337 } catch (IOException ex) { | 368 } catch (MissingResourceException ex) { |
338 answer = key + " (no resource bundle)"; //$NON-NLS-1$ | 369 answer = key ~ " (no resource bundle)"; //$NON-NLS-1$ |
339 } | 370 } |
340 } | 371 } |
341 if (msgs !is null) { | 372 if (msgs !is null) { |
342 try { | 373 try { |
343 MessageFormat formatter = new MessageFormat(""); | 374 char[] frmt = msgs.getString(key); |
344 formatter.applyPattern(msgs.getString(key)); | 375 switch( args.length ){ |
345 answer = formatter.format(args); | 376 case 0: answer = Format(frmt); break; |
377 case 1: answer = Format(frmt, args[0]); break; | |
378 case 2: answer = Format(frmt, args[0], args[1]); break; | |
379 case 3: answer = Format(frmt, args[0], args[1], args[2]); break; | |
380 case 4: answer = Format(frmt, args[0], args[1], args[2], args[3]); break; | |
381 case 5: answer = Format(frmt, args[0], args[1], args[2], args[3], args[4]); break; | |
382 default: | |
383 implMissing(__FILE__, __LINE__ ); | |
384 } | |
346 } catch (MissingResourceException ex2) {} | 385 } catch (MissingResourceException ex2) {} |
347 } | 386 } |
348 return answer; | 387 return answer; |
349 } | 388 } |
350 +/ | 389 |
390 | |
351 /** | 391 /** |
352 * Interrupt the current thread. | 392 * Interrupt the current thread. |
353 * <p> | 393 * <p> |
354 * Note that this is not available on CLDC. | 394 * Note that this is not available on CLDC. |
355 * </p> | 395 * </p> |
366 * @param s1 string | 406 * @param s1 string |
367 * @param s2 string | 407 * @param s2 string |
368 * @return true if the two instances of class String are equal | 408 * @return true if the two instances of class String are equal |
369 */ | 409 */ |
370 public static bool equalsIgnoreCase(String s1, String s2) { | 410 public static bool equalsIgnoreCase(String s1, String s2) { |
371 return s1.equalsIgnoreCase(s2); | 411 String s1b = new char[ s1.length ]; |
372 } | 412 String s2b = new char[ s1.length ]; |
373 | 413 scope(exit){ |
374 } | 414 delete s1b; |
415 delete s2b; | |
416 } | |
417 String s1c = Unicode.toFold( s1, s1b ); | |
418 String s2c = Unicode.toFold( s2, s2b ); | |
419 return s1c == s2c; | |
420 } | |
421 | |
422 } |