1 ! :folding=indent:collapseFolds=0:
5 ! Copyright (C) 2004 Slava Pestov.
7 ! Redistribution and use in source and binary forms, with or without
8 ! modification, are permitted provided that the following conditions are met:
10 ! 1. Redistributions of source code must retain the above copyright notice,
11 ! this list of conditions and the following disclaimer.
13 ! 2. Redistributions in binary form must reproduce the above copyright notice,
14 ! this list of conditions and the following disclaimer in the documentation
15 ! and/or other materials provided with the distribution.
17 ! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 ! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 ! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 ! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 : char? ( obj -- boolean )
34 "java.lang.Character" is ;
36 : >char ( obj -- char )
37 "char" coerce ; inline
39 : string? ( obj -- ? )
40 dup char? swap "java.lang.String" is or ;
42 : str-length ( str -- length )
43 [ ] "java.lang.String" "length" jinvoke ;
45 : substring ( start end str -- str )
46 [ "int" "int" ] "java.lang.String" "substring"
49 : >str ( obj -- string )
50 ! Returns the Java string representation of this object.
51 [ ] "java.lang.Object" "toString" jinvoke ;
53 : >bytes ( string -- array )
54 ! Converts a string to an array of ASCII bytes. An exception
55 ! is thrown if the string contains non-ASCII characters.
57 [ "java.lang.String" ] "java.lang.String" "getBytes"
60 : str-nth ( index str -- char )
61 [ "int" ] "java.lang.String" "charAt" jinvoke ;
63 : >lower ( str -- str )
64 [ ] "java.lang.String" "toLowerCase" jinvoke ;
66 : >upper ( str -- str )
67 [ ] "java.lang.String" "toUpperCase" jinvoke ;
69 : index-of* ( index string substring -- index )
72 ! Why is the first parameter an int and not a char?
74 "java.lang.String" "indexOf"
78 [ "java.lang.String" "int" ]
79 "java.lang.String" "indexOf"
83 : str-compare ( str1 str2 -- n )
84 swap [ "java.lang.String" ] "java.lang.String" "compareTo"