My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gnu.util;

import java.util.StringTokenizer;


/**
* Provide some handy static methods.
*/
public class Misc {
public static final String VERSION = "0.2.0";


//-- linearize array

public static float [] linearize (float [] [] [] src) {
int s1 = src [0] [0].length;
int s2 = src [0].length;
int s3 = src.length;
float [] dst = new float [s1 * s2 * s3];

for (int i=0; i<s3; i++)
for (int j=0; j<s2; j++) {
int offset = s1 * (j + s2 * i);
System.arraycopy (src [i] [j], 0, dst, offset, s1);
}
return dst;
}


//-- string

/** Tokenize a string given a delimiter and from-index. */
public static String [] tokenize (String s, String delim) {
StringTokenizer st = new StringTokenizer (s, delim);

String [] tokens = new String [st.countTokens ()];
for (int i=0; i<tokens.length; i++)
tokens [i] = st.nextToken ();

return tokens;
}

public static String trim (String s) {
if (s == null || s.length () == 0) return s;

int from = 0;
while (from < s.length ())
if (Character.isWhitespace (s.charAt (from))) from++;
else break;
if (from == s.length ()) return "";

int to = s.length () - 1;
while (to > 0)
if (Character.isWhitespace (s.charAt (to))) to--;
else break;

return s.substring (from, to+1);
}

}

Change log

761a0e2f20b2 by marcos on Jun 21, 2010   Diff
Mario Torre review :D
Go to: 
Project members, sign in to write a code review

Older revisions

d47c2d1630ca by marcos roriz <marcosrorizinf> on Jun 14, 2010   Diff
Marked some methods for deletion
e8eea4dc29b4 by marcos on Jun 13, 2010   Diff
gnu.util initial refactoring
770053d1a70c by Roman Kennke <roman.ke...@aicas.com> on May 3, 2007   Diff
Added ant build file, moved sources
into src/ .
All revisions of this file

File info

Size: 1377 bytes, 61 lines
Powered by Google Project Hosting