From: <ipe...@us...> - 2010-03-10 17:55:56
|
Revision: 13327 http://x10.svn.sourceforge.net/x10/?rev=13327&view=rev Author: ipeshansky Date: 2010-03-10 17:55:49 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Cleanup of x10.lang.String. Make String concatenation a proper overloaded operator. Disable special compiler support for string concatenation. String now implements Comparable[String]. Implement String.hashCode() correctly. Implement String.equalsIgnoreCase(), String.toLowerCase(), String.toUpperCase(). Implement String.compareTo(), String.compareToIgnoreCase(). Remove String.format(String,Rail[Any]). Add X10doc comments to String. Add X10doc comment for Any.home. Make Comparable.compareTo() and the operators in Ordered global. Better behavior of isTitleCase() and toTitleCase() on Char. Remove some dead code from char_utils. Point now implements Ordered[Point(rank)]. Modified Paths: -------------- trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java trunk/x10.runtime/src-cpp/x10/lang/String.cc trunk/x10.runtime/src-cpp/x10/lang/String.h trunk/x10.runtime/src-cpp/x10aux/char_utils.cc trunk/x10.runtime/src-x10/x10/lang/Any.x10 trunk/x10.runtime/src-x10/x10/lang/Comparable.x10 trunk/x10.runtime/src-x10/x10/lang/Point.x10 trunk/x10.runtime/src-x10/x10/lang/String.x10 trunk/x10.runtime/src-x10/x10/util/Ordered.x10 Modified: trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java =================================================================== --- trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.compiler/src/x10cpp/visit/MessagePassingCodeGenerator.java 2010-03-10 17:55:49 UTC (rev 13327) @@ -2404,12 +2404,8 @@ // TODO // // Boolean short-circuiting operators are ok -// // FIXME: [IP] string concatenation are ok for now // Assign_c n = asgn; -// assert (opString.equals("&&") || opString.equals("||") || -// (opString.equals("+") && -// (n.left(nf).type().isSubtype(xts.String(), context)) || -// n.right().type().isSubtype(xts.String(), context))) +// assert (opString.equals("&&") || opString.equals("||")) // : "visiting "+n.getClass()+" at "+n.position()+": "+n; if (opString.equals(">>>=")) { @@ -4647,12 +4643,8 @@ String opString = n.operator().toString(); // Boolean short-circuiting operators are ok - // FIXME: [IP] string concatenation are ok for now X10TypeSystem_c xts = (X10TypeSystem_c) tr.typeSystem(); - assert (opString.equals("&&") || opString.equals("||") || - (opString.equals("+") && - (n.left().type().isSubtype(xts.String(), tr.context())) || - n.right().type().isSubtype(xts.String(), tr.context()))) + assert (opString.equals("&&") || opString.equals("||")) : "visiting "+n.getClass()+" at "+n.position()+": "+n; n.printSubExpr(n.left(), true, sw, tr); Modified: trunk/x10.runtime/src-cpp/x10/lang/String.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/String.cc 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-cpp/x10/lang/String.cc 2010-03-10 17:55:49 UTC (rev 13327) @@ -17,6 +17,7 @@ #include <x10aux/basic_functions.h> #include <x10aux/throw.h> #include <x10aux/hash.h> +#include <x10aux/char_utils.h> #include <x10/lang/String.h> #include <x10/lang/Rail.h> @@ -44,7 +45,15 @@ } x10_int String::hashCode() { - return x10aux::hash(reinterpret_cast<const unsigned char*>(FMGL(content)), length()); + //return x10aux::hash(reinterpret_cast<const unsigned char*>(FMGL(content)), length()); + x10_int hc = 0; + x10_int l = length(); + const unsigned char* k = reinterpret_cast<const unsigned char*>(FMGL(content)); + for (; l > 0; k++, l--) { + hc *= 31; + hc += (x10_int) *k; + } + return hc; } x10_int String::indexOf(ref<String> str, x10_int i) { @@ -268,11 +277,83 @@ if (ref<String>(p0).operator->() == this) return true; // short-circuit trivial equality if (!x10aux::instanceof<ref<x10::lang::String> >(p0)) return false; ref<String> that = (ref<String>) p0; + if (this->FMGL(content_length) != that->FMGL(content_length)) return false; // short-circuit trivial dis-equality if (strcmp(this->FMGL(content), that->FMGL(content))) return false; return true; } +#ifdef __CYGWIN__ +extern "C" int strcasecmp(const char *, const char *); +#endif + +/* FIXME: Unicode support */ +x10_boolean String::equalsIgnoreCase(ref<String> s) { + nullCheck(s); + if (ref<String>(s).operator->() == this) return true; // short-circuit trivial equality + if (this->FMGL(content_length) != s->FMGL(content_length)) return false; // short-circuit trivial dis-equality + if (strcasecmp(this->FMGL(content), s->FMGL(content))) + return false; + return true; +} + +/* FIXME: Unicode support */ +ref<String> String::toLowerCase() { + char *str = x10aux::alloc<char>(FMGL(content_length)+1); + bool all_lower = true; + for (std::size_t i=0 ; i<FMGL(content_length) ; ++i) { + x10_char c = FMGL(content)[i]; + if (!x10aux::char_utils::isLowerCase(c)) + all_lower = false; + x10_char l = x10aux::char_utils::toLowerCase(c); + str[i] = (char)l.v; + } + if (all_lower) { + x10aux::dealloc(str); + return this; + } + str[FMGL(content_length)] = '\0'; + return String::Steal(str); +} + +/* FIXME: Unicode support */ +ref<String> String::toUpperCase() { + char *str = x10aux::alloc<char>(FMGL(content_length)+1); + bool all_upper = true; + for (std::size_t i=0 ; i<FMGL(content_length) ; ++i) { + x10_char c = FMGL(content)[i]; + if (!x10aux::char_utils::isUpperCase(c)) + all_upper = false; + x10_char u = x10aux::char_utils::toUpperCase(c); + str[i] = (char)u.v; + } + if (all_upper) { + x10aux::dealloc(str); + return this; + } + str[FMGL(content_length)] = '\0'; + return String::Steal(str); +} + +x10_int String::compareTo(ref<String> s) { + nullCheck(s); + if (ref<String>(s).operator->() == this) return 0; // short-circuit trivial equality + int length_diff = this->FMGL(content_length) - s->FMGL(content_length); + if (length_diff != 0) + return length_diff; + return (x10_int) strcmp(this->FMGL(content), s->FMGL(content)); +} + +/* FIXME: Unicode support */ +x10_int String::compareToIgnoreCase(ref<String> s) { + nullCheck(s); + if (ref<String>(s).operator->() == this) return 0; // short-circuit trivial equality + int length_diff = this->FMGL(content_length) - s->FMGL(content_length); + if (length_diff != 0) + return length_diff; + return (x10_int) strcasecmp(this->FMGL(content), s->FMGL(content)); +} + const serialization_id_t String::_serialization_id = DeserializationDispatcher::addDeserializer(String::_deserializer<Object>); @@ -315,9 +396,13 @@ Fun_0_1<x10_int, x10_char>::itable<String> String::_itable_Fun_0_1(&String::apply, &String::at, &String::at, &String::equals, &String::hashCode, &String::home, &String::toString, &String::typeName); - -x10aux::itable_entry String::_itables[2] = { +Comparable<ref<String> >::itable<String> String::_itable_Comparable(&String::at, &String::at, &String::compareTo, + &String::equals, &String::hashCode, + &String::home, &String::toString, &String::typeName); + +x10aux::itable_entry String::_itables[3] = { x10aux::itable_entry(&Fun_0_1<x10_int, x10_char>::rtt, &String::_itable_Fun_0_1), + x10aux::itable_entry(&Comparable<ref<String> >::rtt, &String::_itable_Comparable), x10aux::itable_entry(NULL, (void*)x10aux::getRTT<String>()) }; Modified: trunk/x10.runtime/src-cpp/x10/lang/String.h =================================================================== --- trunk/x10.runtime/src-cpp/x10/lang/String.h 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-cpp/x10/lang/String.h 2010-03-10 17:55:49 UTC (rev 13327) @@ -19,6 +19,7 @@ #include <x10/lang/Object.h> #include <x10/lang/Fun_0_1.h> +#include <x10/lang/Comparable.h> #ifdef __CYGWIN__ extern "C" char *strdup (const char *); @@ -42,8 +43,9 @@ RTT_H_DECLS_CLASS; - static Fun_0_1<x10_int/*nat*/, x10_char>::itable<String> _itable_Fun_0_1; - static x10aux::itable_entry _itables[2]; + static Fun_0_1<x10_int, x10_char>::itable<String> _itable_Fun_0_1; + static Comparable<x10aux::ref<String> >::itable<String> _itable_Comparable; + static x10aux::itable_entry _itables[3]; virtual x10aux::itable_entry* _getITables() { return _itables; } // Set steal to true if you have just allocated the char * with @@ -142,6 +144,16 @@ virtual x10_boolean equals(x10aux::ref<x10::lang::Any> p0); + x10_boolean equalsIgnoreCase(x10aux::ref<x10::lang::String> s); + + x10aux::ref<String> toLowerCase(); + + x10aux::ref<String> toUpperCase(); + + x10_int compareTo(x10aux::ref<x10::lang::String> s); + + x10_int compareToIgnoreCase(x10aux::ref<x10::lang::String> s); + String () : FMGL(content)(NULL) { } virtual ~String () { x10aux::dealloc(FMGL(content)); Modified: trunk/x10.runtime/src-cpp/x10aux/char_utils.cc =================================================================== --- trunk/x10.runtime/src-cpp/x10aux/char_utils.cc 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-cpp/x10aux/char_utils.cc 2010-03-10 17:55:49 UTC (rev 13327) @@ -31,8 +31,7 @@ } x10_boolean x10aux::char_utils::isTitleCase(x10_char x) { - (void) x; - assert(false); /* FIXME: STUBBED NATIVE */ + /* FIXME: Proper title case support */ return false; } @@ -96,12 +95,7 @@ } x10_char x10aux::char_utils::toTitleCase(x10_char x) { - (void) x; - assert(false); /* FIXME: STUBBED NATIVE */ - return x; + /* FIXME: Proper title case support */ + return toUpperCase(x); } - -x10_char x10aux::char_utils::reverseBytes(x10_char x) { - return ((x.v&0x00FF)<<8)|((x.v&0xFF00)>>8); -} // vim:tabstop=4:shiftwidth=4:expandtab Modified: trunk/x10.runtime/src-x10/x10/lang/Any.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-x10/x10/lang/Any.x10 2010-03-10 17:55:49 UTC (rev 13327) @@ -26,10 +26,15 @@ */ @NativeRep("java", "java.lang.Object", null, null) @NativeRep("c++", "x10aux::ref<x10::lang::Any>", "x10::lang::Any", null) -public interface Any( @Native("java", "x10.lang.Place.place(x10.core.Ref.home(#0))") - @Native("c++", - "x10::lang::Place_methods::place(x10aux::get_location(#0))") - home: Place) { +public interface Any( + /** + * The home location of this entity. + * This will be 'here' for non-object entities. + */ + @Native("java", "x10.lang.Place.place(x10.core.Ref.home(#0))") + @Native("c++", "x10::lang::Place_methods::place(x10aux::get_location(#0))") + home: Place +) { /** * Return the home location of this entity. Modified: trunk/x10.runtime/src-x10/x10/lang/Comparable.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Comparable.x10 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-x10/x10/lang/Comparable.x10 2010-03-10 17:55:49 UTC (rev 13327) @@ -11,6 +11,7 @@ package x10.lang; +// FIXME: fold into Ordered[T] /** * This interface imposes a total ordering on the entities of each type that implements it. * @@ -35,7 +36,7 @@ * @return a negative integer, zero, or a positive integer if this entity is less than, equal * to, or greater than the given entity. */ - def compareTo(that:T):Int; + global def compareTo(that:T):Int; } // vim:shiftwidth=4:tabstop=4:expandtab Modified: trunk/x10.runtime/src-x10/x10/lang/Point.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/Point.x10 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-x10/x10/lang/Point.x10 2010-03-10 17:55:49 UTC (rev 13327) @@ -11,6 +11,8 @@ package x10.lang; +import x10.util.Ordered; + /** * The type <code>Point(rank)</code> represents a point in a * rank-dimensional space. The coordiIntes of a point <code>p</code> @@ -22,7 +24,7 @@ * @author bdlucas * @author vj */ -final public class Point(rank: Int) implements (Int) => Int { +final public class Point(rank: Int) implements (Int) => Int, Ordered[Point(rank)] { /** * Returns the value of the ith coordiInte. Modified: trunk/x10.runtime/src-x10/x10/lang/String.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/lang/String.x10 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-x10/x10/lang/String.x10 2010-03-10 17:55:49 UTC (rev 13327) @@ -13,80 +13,379 @@ import x10.compiler.Native; import x10.compiler.NativeRep; +import x10.util.Ordered; -// TODO: comparison operators +/** + * The String class represents character strings. + * All string literals in X10 programs, such as "Hello", are instances of String. + * Strings are immutable and cannot be changed after they are created. + * + * String provides a concatenation operator '+', methods for converting + * instances of other types to strings (which invoke the + * {@link x10.lang.Any#toString()} method), methods for examining individual + * characters of the sequence, for searching strings, for comparing + * strings, for extracting substrings, and for creating a copy of a string + * with all characters translated to uppercase or to lowercase. Case mapping + * is defined in {@link x10.lang.Char}. + */ @NativeRep("java", "java.lang.String", "x10.core.BoxedString", null) @NativeRep("c++", "x10aux::ref<x10::lang::String>", "x10::lang::String", null) -public final class String implements (Int) => Char { - // TODO: constructors +public final class String implements (Int) => Char/*TODO, (Range) => String*//*TODO, Ordered[String]*/, Comparable[String] { + /** + * Default constructor. + */ public native def this(): String; + + /** + * Copy constructor. + */ public native def this(String): String; - + + + /** + * Return true if the given entity is a String, and this String is equal + * to the given entity. + * @param x the given entity + * @return true if this String is equal to the given entity. + */ @Native("java", "(#0).equals(#1)") @Native("c++", "x10aux::equals(#0,#1)") public native global safe def equals(Any): boolean; - + + // FIXME: Locale sensitivity + /** + * Returns true if this String is equal to the given String, ignoring case considerations. + * @param x the given String + * @return true if this String is equal to the given String ignoring case. + */ + @Native("java", "(#0).equalsIgnoreCase(#1)") + @Native("c++", "(#0)->equalsIgnoreCase(#1)") + public native global def equalsIgnoreCase(String): boolean; + + /** + * Returns a hash code for this String. + * The hash code for a String object is computed as + * <pre> + * s(0).ord()*31^(n-1) + s(1).ord()*31^(n-2) + ... + s(n-1).ord() + * </pre> + * using integer arithmetic, where s(i) is the ith character of the string, + * n is the length of the string, and ^ indicates exponentiation. + * (The hash value of the empty string is zero.) + * @return a hash code value for this String. + */ @Native("java", "(#0).hashCode()") @Native("c++", "x10aux::hash_code(#0)") public native global safe def hashCode(): int; - + + + /** + * Returns this String. + * @return the String itself. + */ @Native("java", "(#0).toString()") @Native("c++", "x10aux::to_string(#0)") public native global safe def toString(): String; - - @Native("java", "#0.length()") - @Native("c++", "#0->length()") + + + /** + * Returns the length of this String. + * @return the length of this String. + */ + @Native("java", "(#0).length()") + @Native("c++", "(#0)->length()") public native global def length(): Int; - + + /** + * Returns the Char at the specified index in this String. + * An index ranges from 0 to length()-1. + * @param index the index of the Char + * @return the Char at the specified (0-based) index of this String. + * @see #charAt(Int) + */ @Native("java", "(#0).charAt(#1)") @Native("c++", "(#0)->charAt(#1)") public native global def apply(index: Int): Char; + /** + * Returns the Char at the specified index in this String. + * An index ranges from 0 to length()-1. + * @param index the index of the Char + * @return the Char at the specified (0-based) index of this String. + * @see #apply(Int) + */ @Native("java", "(#0).charAt(#1)") @Native("c++", "(#0)->charAt(#1)") public native global def charAt(index: Int): Char; - - @Native("java", "x10.core.RailFactory.<java.lang.Character>makeValRailFromJavaArray(#0.toCharArray())") + + /** + * Converts this String to a ValRail of Chars. + * @return a ValRail of Chars whose length is the length of this String and + * whose contents are initialized to contain the Chars in this String. + * @see #bytes() + */ + @Native("java", "x10.core.RailFactory.<java.lang.Character>makeValRailFromJavaArray((#0).toCharArray())") @Native("c++", "(#0)->chars()") public native global def chars(): ValRail[Char]; - - @Native("java", "x10.core.RailFactory.<java.lang.Byte>makeValRailFromJavaArray(#0.getBytes())") + + /** + * Encodes this String into a sequence of Bytes using the platform's default charset. + * @return the ValRail of Bytes representing this String in the default charset. + * @see #chars() + */ + @Native("java", "x10.core.RailFactory.<java.lang.Byte>makeValRailFromJavaArray((#0).getBytes())") @Native("c++", "(#0)->bytes()") public native global def bytes(): ValRail[Byte]; - - @Native("java", "#0.substring(#1, #2)") + + /** + * Returns a new String that is a substring of this String. + * The substring begins at the specified fromIndex and extends to the Char at index toIndex-1. + * Thus the length of the substring is toIndex-fromIndex. + * @param fromIndex the starting index, inclusive + * @param toIndex the ending index, exclusive + * @return the specified substring. + */ + @Native("java", "(#0).substring(#1, #2)") @Native("c++", "(#0)->substring(#1, #2)") public native global def substring(fromIndex: Int, toIndex: Int): String; - - @Native("java", "#0.indexOf(#1)") + + + /** + * Returns the index within this String of the first occurrence of the specified Char ch. + * If the Char ch occurs in this String, then the index of the first such occurrence is returned. + * This index is the smallest value k such that: + * <pre> + * this(k) == ch + * </pre> + * is true. + * If no such Char occurs in this String, then -1 is returned. + * @param ch the given Char + * @return the index of the first occurrence of the Char in this String, or -1 if the Char does not occur. + * @see #indexOf(String) + * @see #lastIndexOf(Char) + */ + @Native("java", "(#0).indexOf(#1)") @Native("c++", "(#0)->indexOf(#1)") - public native global def indexOf(Char): Int; - - @Native("java", "#0.indexOf(#1)") + public native global def indexOf(ch: Char): Int; + + /** + * Returns the index within this String of the first occurrence of the specified substring. + * The Int returned is the smallest value k such that + * <pre> + * this.substring(k, k+str.length()).equals(str) + * </pre> + * is true. + * @param str the substring to search for + * @return if the String argument occurs as a substring within this object, + * then the index of the first character of the first such substring + * is returned. If it does not occur as a substring, -1 is returned. + * @see #indexOf(Char) + * @see #lastIndexOf(String) + */ + @Native("java", "(#0).indexOf(#1)") @Native("c++", "(#0)->indexOf(#1)") - public native global def indexOf(String): Int; - - @Native("java", "#0.lastIndexOf(#1)") + public native global def indexOf(str: String): Int; + + /** + * Returns the index within this String of the last occurrence of the specified Char ch. + * If the Char ch occurs in this String, then the index of the last such occurrence is returned. + * This index is the largest value k such that: + * <pre> + * this(k) == ch + * </pre> + * is true. + * If no such Char occurs in this String, then -1 is returned. + * The String is searched backwards starting at the last Char. + * @param ch the given Char + * @return the index of the last occurrence of the Char in this String, or -1 if the Char does not occur. + * @see #lastIndexOf(String) + * @see #indexOf(Char) + */ + @Native("java", "(#0).lastIndexOf(#1)") @Native("c++", "(#0)->lastIndexOf(#1)") - public native global def lastIndexOf(Char): Int; + public native global def lastIndexOf(ch: Char): Int; - @Native("java", "#0.lastIndexOf(#1)") + /** + * Returns the index within this String of the rightmost occurrence of the specified substring. + * The rightmost empty string "" is considered to occur at the index value this.length(). + * The returned index is the largest value k such that + * <pre> + * this.substring(k, k+str.length()).equals(str) + * </pre> + * is true. + * @param str the substring to search for + * @return if the String argument occurs one or more times as a substring + * within this object, then the index of the first character of the + * last such substring is returned. If it does not occur as a + * substring, -1 is returned. + * @see #lastIndexOf(Char) + * @see #indexOf(String) + */ + @Native("java", "(#0).lastIndexOf(#1)") @Native("c++", "(#0)->lastIndexOf(#1)") - public native global def lastIndexOf(String): Int; + public native global def lastIndexOf(str: String): Int; - @Native("java", "x10.core.RailFactory.makeValRailFromJavaArray(#0.split(#1))") + + /** + * Splits this String around matches of the given regular expression. + * Trailing empty strings are not included in the resulting ValRail. + * @param regex the delimiting regular expression. + * @return the ValRail of Strings computed by splitting this String around matches of the given regular expression. + */ + @Native("java", "x10.core.RailFactory.makeValRailFromJavaArray((#0).split(#1))") @Native("c++", "(#0)->split(#1)") - public native global def split(String): ValRail[String]; + public native global def split(regex: String): ValRail[String]; + + /** + * Returns the String representation of the given entity. + * The representation is exactly the one returned by the toString() method of the entity. + * @param v the given entity + * @return a String representation of the given entity. + */ @Native("java", "java.lang.String.valueOf(#4)") @Native("c++", "x10aux::safe_to_string(#4)") - public native static def valueOf[T](T):String; - - @Native("java", "java.lang.String.format(#1, #2.getBoxedArray())") + public native static def valueOf[T](v: T): String; + + + /** + * Returns a formatted String using the specified format String and arguments. + * The only format specifiers supported at the moment are those common to Java's String.format() and C++'s printf. + * If there are more arguments than format specifiers, the extra arguments are ignored. + * The number of arguments is variable and may be zero. + * The behaviour on a null argument depends on the conversion. + * @param fmt the format String + * @param args the arguments referenced by the format specifiers in the format string. + * @return a formatted string. + */ + @Native("java", "java.lang.String.format(#1,(#2).getBoxedArray())") @Native("c++", "x10::lang::String::format(#1,#2)") - public native static def format(fmt: String, Rail[Any]): String; - - @Native("java", "java.lang.String.format(#1, #2.getBoxedArray())") - @Native("c++", "x10::lang::String::format(#1,#2)") - public native static def format(fmt: String, ValRail[Any]): String; + public native static def format(fmt: String, args: ValRail[Any]): String; + + + // FIXME: Locale sensitivity + /** + * Converts all of the Chars in this String to lower case. + * @return this String, converted to lowercase. + */ + @Native("java", "(#0).toLowerCase()") + @Native("c++", "(#0)->toLowerCase()") + public native global def toLowerCase(): String; + + // FIXME: Locale sensitivity + /** + * Converts all of the Chars in this String to upper case. + * @return this String, converted to uppercase. + */ + @Native("java", "(#0).toUpperCase()") + @Native("c++", "(#0)->toUpperCase()") + public native global def toUpperCase(): String; + + + /** + * Compares this String with another String lexicographically. + * The result is a negative integer if this String lexicographically precedes the argument String. + * The result is a positive integer if this String lexicographically follows the argument String. + * The result is zero if the Strings are equal; compareTo returns 0 exactly when the equals(Any) method would return true. + * <p/> + * This method compares the Chars in this String and the argument String at all indexes from 0 to the length of the shorter of the two strings. + * If the Chars at some index k are not equal, the method returns the difference in ordinal values of those Chars: + * <pre> + * this(k).ord() - arg(k).ord() + * </pre> + * If there is no index position at which the Chars differ, then the method returns the difference of the lengths of the two strings: + * <pre> + * this.length() - arg.length() + * </pre> + * @param arg the argument String + * @return 0 if the argument String is equal to this String; a negative Int if this String is lexicographically less than the argument String; and a positive Int if this String is lexicographically greater than the argument String. + */ + @Native("java", "(#0).compareTo(#1)") + @Native("c++", "(#0)->compareTo(#1)") + public native global def compareTo(arg: String): Int; + + // FIXME: Locale sensitivity + /** + * Compares this String with another String lexicographically, ignoring case differences. + * This method returns an integer whose sign is that of calling {@link #compareTo(String)} + * with normalized versions of the Strings where case differences have been eliminated, + * e.g., by calling s.toLowerCase().toUpperCase() on each String. + * @param arg the argument String + * @return a negative Int, zero, or a positive Int as the argument String is greater than, equal to, or less than this String, ignoring case considerations. + */ + @Native("java", "(#0).compareToIgnoreCase(#1)") + @Native("c++", "(#0)->compareToIgnoreCase(#1)") + public native global def compareToIgnoreCase(arg: String): Int; + + + // FIXME: Locale sensitivity + /** + * A less-than operator. + * Compares this String with another String and returns true if this String is + * strictly before the other String in dictionary order. + * @param x the other String + * @return true if this String is strictly before the other String. + */ + @Native("java", "((#0).compareTo(#1) < 0)") + @Native("c++", "((#0)->compareTo(#1) < 0)") + public native global safe operator this < (x:String): Boolean; + + // FIXME: Locale sensitivity + /** + * A greater-than operator. + * Compares this String with another String and returns true if this String is + * strictly after the other String in dictionary order. + * @param x the other String + * @return true if this String is strictly after the other String. + */ + @Native("java", "((#0).compareTo(#1) > 0)") + @Native("c++", "((#0)->compareTo(#1) > 0)") + public native global safe operator this > (x:String): Boolean; + + // FIXME: Locale sensitivity + /** + * A less-than-or-equal-to operator. + * Compares this String with another String and returns true if this String is + * equal to the other String or is before it in dictionary order. + * @param x the other String + * @return true if this String is before or equal to the other String. + */ + @Native("java", "((#0).compareTo(#1) <= 0)") + @Native("c++", "((#0)->compareTo(#1) <= 0)") + public native global safe operator this <= (x:String): Boolean; + + // FIXME: Locale sensitivity + /** + * A greater-than-or-equal-to operator. + * Compares this String with another String and returns true if this String is + * equal to the other String or is after it in dictionary order. + * @param x the other String + * @return true if this String is after or equal to the other String. + */ + @Native("java", "((#0).compareTo(#1) >= 0)") + @Native("c++", "((#0)->compareTo(#1) >= 0)") + public native global safe operator this >= (x:String): Boolean; + + /** + * A string concatenation operator. + * Appends the given entity to the given String by calling the entity's + * {@link x10.lang.Any#toString()} method. + * @param x the given String + * @param y the given entity + * @return the resulting String + */ + @Native("java", "((#4) + (#5))") + @Native("c++", "((#4) + (#5))") + public native static safe operator[T] (x:String) + (y:T): String; + + /** + * A string concatenation operator. + * Prepends the given entity to the given String by calling the entity's + * {@link x10.lang.Any#toString()} method. + * @param x the given entity + * @param y the given String + * @return the resulting String + */ + @Native("java", "((#4) + (#5))") + @Native("c++", "((#4) + (#5))") + public native static safe operator[T] (x:T) + (y:String): String; } Modified: trunk/x10.runtime/src-x10/x10/util/Ordered.x10 =================================================================== --- trunk/x10.runtime/src-x10/x10/util/Ordered.x10 2010-03-10 17:07:38 UTC (rev 13326) +++ trunk/x10.runtime/src-x10/x10/util/Ordered.x10 2010-03-10 17:55:49 UTC (rev 13327) @@ -24,7 +24,7 @@ * @param that the other entity * @return true if the current entity is strictly less than the other entity. */ - operator this < (that: T): Boolean; + global operator this < (that: T): Boolean; /** * A binary greater-than operator. * Compares the two operands and returns true if the left-hand operand @@ -33,7 +33,7 @@ * @param that the other entity * @return true if the current entity is strictly greater than the other entity. */ - operator this > (that: T): Boolean; + global operator this > (that: T): Boolean; /** * A binary less-than-or-equal-to operator. * Compares the two operands and returns true if the left-hand operand @@ -42,7 +42,7 @@ * @param that the other entity * @return true if the current entity is less than or equal to the other entity. */ - operator this <= (that: T): Boolean; + global operator this <= (that: T): Boolean; /** * A binary greater-than-or-equal-to operator. * Compares the two operands and returns true if the left-hand operand @@ -51,5 +51,5 @@ * @param that the other entity * @return true if the current entity is greater than or equal to the other entity. */ - operator this >= (that: T): Boolean; + global operator this >= (that: T): Boolean; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |