annotate dwt/internal/Compatibility.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
1 /*******************************************************************************
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module dwt.internal.Compatibility;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 /+
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16 import java.io.*;
213
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
17 import java.io.File;
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import java.text.MessageFormat;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 import java.util.MissingResourceException;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 import java.util.ResourceBundle;
213
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
21 import java.util.zip.DeflaterOutputStream;
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 import java.util.zip.InflaterInputStream;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 +/
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 import dwt.DWT;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 public import dwt.dwthelper.FileInputStream;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 public import dwt.dwthelper.FileOutputStream;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 public import dwt.dwthelper.InflaterInputStream;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 import Math = tango.math.Math;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 import Unicode = tango.text.Unicode;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 import tango.sys.Process;
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
33 import dwt.dwthelper.utils;
213
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
34 import tango.io.Path;
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 * This class is a placeholder for utility methods commonly
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 * used on J2SE platforms but not supported on some J2ME
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 * profiles.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 * It is part of our effort to provide support for both J2SE
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 * and J2ME platforms.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 * </p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 * IMPORTANT: some of the methods have been modified from their
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 * J2SE parents. Refer to the description of each method for
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47 * specific changes.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 * </p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 * <ul>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 * <li>Exceptions thrown may differ since J2ME's set of
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 * exceptions is a subset of J2SE's one.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52 * </li>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 * <li>The range of the mathematic functions is subject to
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 * change.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 * </li>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 * </ul>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 public final class Compatibility {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 * Returns the PI constant as a double.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 public static const real PI = Math.PI;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 static const real toRadians = PI / 180;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 * Answers the length of the side adjacent to the given angle
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 * of a right triangle. In other words, it returns the integer
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 * conversion of length * cos (angle).
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 * IMPORTANT: the j2me version has an additional restriction on
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 * the argument. length must be between -32767 and 32767 (inclusive).
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 * </p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 * @param angle the angle in degrees
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 * @param length the length of the triangle's hypotenuse
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 * @return the integer conversion of length * cos (angle)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 public static int cos(int angle, int length) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 return cast(int)(Math.cos(angle * toRadians) * length);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 * Answers the length of the side opposite to the given angle
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86 * of a right triangle. In other words, it returns the integer
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 * conversion of length * sin (angle).
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 * IMPORTANT: the j2me version has an additional restriction on
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 * the argument. length must be between -32767 and 32767 (inclusive).
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 * </p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 * @param angle the angle in degrees
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 * @param length the length of the triangle's hypotenuse
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95 * @return the integer conversion of length * sin (angle)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 public static int sin(int angle, int length) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 return cast(int)(Math.sin(angle * toRadians) * length);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
99 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102 * Answers the most negative (i.e. closest to negative infinity)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 * integer value which is greater than the number obtained by dividing
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 * the first argument p by the second argument q.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 * @param p numerator
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107 * @param q denominator (must be different from zero)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 * @return the ceiling of the rational number p / q.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
109 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
110 public static int ceil(int p, int q) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111 return cast(int)Math.ceil(cast(float)p / q);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
112 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114 /**
213
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
115 * Answers whether the indicated file exists or not.
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
116 *
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
117 * @param parent the file's parent directory
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
118 * @param child the file's name
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
119 * @return true if the file exists
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
120 */
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
121 public static bool fileExists(String parent, String child) {
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
122 return FS.exists( FS.join(parent, child));
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
123 }
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
124
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
125 /**
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
126 * Answers the most positive (i.e. closest to positive infinity)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
127 * integer value which is less than the number obtained by dividing
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
128 * the first argument p by the second argument q.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
129 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
130 * @param p numerator
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
131 * @param q denominator (must be different from zero)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
132 * @return the floor of the rational number p / q.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
133 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
134 public static int floor(int p, int q) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
135 return cast(int)Math.floor(cast(double)p / q);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
136 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
137
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
138 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
139 * Answers the result of rounding to the closest integer the number obtained
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
140 * by dividing the first argument p by the second argument q.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
141 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
142 * IMPORTANT: the j2me version has an additional restriction on
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
143 * the arguments. p must be within the range 0 - 32767 (inclusive).
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
144 * q must be within the range 1 - 32767 (inclusive).
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
145 * </p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
146 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
147 * @param p numerator
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
148 * @param q denominator (must be different from zero)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
149 * @return the closest integer to the rational number p / q
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
150 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
151 public static int round(int p, int q) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
152 return cast(int)Math.round(cast(float)p / q);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
153 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
154
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
155 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
156 * Returns 2 raised to the power of the argument.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
157 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
158 * @param n an int value between 0 and 30 (inclusive)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
159 * @return 2 raised to the power of the argument
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
160 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
161 * @exception IllegalArgumentException <ul>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
162 * <li>ERROR_INVALID_RANGE - if the argument is not between 0 and 30 (inclusive)</li>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
163 * </ul>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
164 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
165 public static int pow2(int n) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
166 if (n >= 1 && n <= 30)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
167 return 2 << (n - 1);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
168 else if (n != 0) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
169 DWT.error(DWT.ERROR_INVALID_RANGE);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
170 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
171 return 1;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
172 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
173
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
174 /**
213
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
175 * Create an DeflaterOutputStream if such things are supported.
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
176 *
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
177 * @param stream the output stream
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
178 * @return a deflater stream or <code>null</code>
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
179 * @exception IOException
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
180 *
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
181 * @since 3.4
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
182 */
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
183 public static OutputStream newDeflaterOutputStream(OutputStream stream) {
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
184 //DWT_TODO
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
185 implMissing(__FILE__,__LINE__);
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
186 return null;
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
187 //return new DeflaterOutputStream(stream);
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
188 }
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
189
36f5cb12e1a2 Update to SWT 3.4M7
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
190 /**
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
191 * Open a file if such things are supported.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
192 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
193 * @param filename the name of the file to open
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
194 * @return a stream on the file if it could be opened.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
195 * @exception IOException
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
196 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
197 public static InputStream newFileInputStream(String filename) {
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
198 return new FileInputStream(filename);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
199 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
200
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
201 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
202 * Open a file if such things are supported.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
203 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
204 * @param filename the name of the file to open
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
205 * @return a stream on the file if it could be opened.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
206 * @exception IOException
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
207 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
208 public static OutputStream newFileOutputStream(String filename) {
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
209 return new FileOutputStream(filename);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
210 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
211
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
212 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
213 * Create an InflaterInputStream if such things are supported.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
214 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
215 * @param stream the input stream
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
216 * @return a inflater stream or <code>null</code>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
217 * @exception IOException
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
218 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
219 * @since 3.3
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
220 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
221 public static InflaterInputStream newInflaterInputStream(InputStream stream) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
222 return new InflaterInputStream(stream);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
223 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
224
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
225 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
226 * Answers whether the character is a letter.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
227 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
228 * @param c the character
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
229 * @return true when the character is a letter
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
230 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
231 public static bool isLetter(dchar c) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
232 return Unicode.isLetter(c);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
233 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
234
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
235 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
236 * Answers whether the character is a letter or a digit.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
237 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
238 * @param c the character
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
239 * @return true when the character is a letter or a digit
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
240 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
241 public static bool isLetterOrDigit(dchar c) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
242 return Unicode.isLetterOrDigit(c);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
243 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
244
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
245 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
246 * Answers whether the character is a Unicode space character.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
247 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
248 * @param c the character
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
249 * @return true when the character is a Unicode space character
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
250 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
251 public static bool isSpaceChar(dchar c) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
252 return Unicode.isSpace(c);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
253 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
254
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
255 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
256 * Answers whether the character is a whitespace character.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
257 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
258 * @param c the character to test
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
259 * @return true if the character is whitespace
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
260 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
261 public static bool isWhitespace(dchar c) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
262 return Unicode.isWhitespace(c);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
263 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
264
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
265 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
266 * Execute a program in a separate platform process if the
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
267 * underlying platform support this.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
268 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
269 * The new process inherits the environment of the caller.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
270 * </p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
271 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
272 * @param prog the name of the program to execute
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
273 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
274 * @exception ProcessException
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
275 * if the program cannot be executed
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
276 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
277 public static void exec(String prog) {
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
278 auto proc = new Process( prog );
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
279 proc.execute;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
280 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
281
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
282 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
283 * Execute progArray[0] in a separate platform process if the
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
284 * underlying platform support this.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
285 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
286 * The new process inherits the environment of the caller.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
287 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
288 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
289 * @param progArray array containing the program to execute and its arguments
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
290 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
291 * @exception ProcessException
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
292 * if the program cannot be executed
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
293 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
294 public static void exec(String[] progArray) {
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
295 auto proc = new Process( progArray );
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
296 proc.execute;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
297 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
298 /++ PORTING_LEFT
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
299 private static ResourceBundle msgs = null;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
300
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
301 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
302 * Returns the NLS'ed message for the given argument. This is only being
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
303 * called from DWT.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
304 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
305 * @param key the key to look up
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
306 * @return the message for the given key
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
307 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
308 * @see DWT#getMessage(String)
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
309 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
310 public static String getMessage(String key) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
311 String answer = key;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
312
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
313 if (key == null) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
314 DWT.error (DWT.ERROR_NULL_ARGUMENT);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
315 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
316 if (msgs == null) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
317 try {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
318 msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
319 } catch (MissingResourceException ex) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
320 answer = key + " (no resource bundle)"; //$NON-NLS-1$
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
321 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
322 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
323 if (msgs != null) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
324 try {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
325 answer = msgs.getString(key);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
326 } catch (MissingResourceException ex2) {}
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
327 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
328 return answer;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
329 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
330
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
331 public static String getMessage(String key, Object[] args) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
332 String answer = key;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
333
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
334 if (key == null || args == null) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
335 DWT.error (DWT.ERROR_NULL_ARGUMENT);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
336 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
337 if (msgs == null) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
338 try {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
339 msgs = ResourceBundle.getBundle("dwt.internal.SWTMessages"); //$NON-NLS-1$
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
340 } catch (MissingResourceException ex) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
341 answer = key + " (no resource bundle)"; //$NON-NLS-1$
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
342 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
343 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
344 if (msgs != null) {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
345 try {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
346 MessageFormat formatter = new MessageFormat("");
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
347 formatter.applyPattern(msgs.getString(key));
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
348 answer = formatter.format(args);
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
349 } catch (MissingResourceException ex2) {}
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
350 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
351 return answer;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
352 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
353 ++/
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
354
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
355
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
356 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
357 * Interrupt the current thread.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
358 * <p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
359 * Note that this is not available on CLDC.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
360 * </p>
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
361 */
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
362 public static void interrupt() {
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
363 //PORTING_FIXME: how to implement??
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
364 //Thread.currentThread().interrupt();
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
365 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
366
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
367 /**
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
368 * Compares two instances of class String ignoring the case of the
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
369 * characters and answers if they are equal.
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
370 *
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
371 * @param s1 string
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
372 * @param s2 string
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
373 * @return true if the two instances of class String are equal
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
374 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
375 public static bool equalsIgnoreCase(String s1, String s2) {
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
376 String s1b = new char[ s1.length ];
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
377 String s2b = new char[ s1.length ];
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
378 scope(exit){
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
379 delete s1b;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
380 delete s2b;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
381 }
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
382 String s1c = Unicode.toFold( s1, s1b );
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 2
diff changeset
383 String s2c = Unicode.toFold( s2, s2b );
2
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
384 return s1c == s2c;
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
385 }
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
386
57151e2793a2 More common modules from dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
387 }