com.blackperl.Perl
Class Lcfirst

java.lang.Object
  |
  +--com.blackperl.Perl.Lcfirst

public final class Lcfirst
extends java.lang.Object

Static-method implementation of the Perl lcfirst keyword. The class provides several static methods to emulate Perl's lcfirst. In keeping with the philosophy of not directly replicating Java functionality, there is no implementation of lc. Rather, the developer should use the toLowerCase method of the String class. The methods actually use the toLowerCase method to do the needed conversions. Thus, each version of lcfirst also has a form that takes a Locale object as an additional parameter, to dictate the rules for converting the characters to lower-case.

Some simple examples:

     import com.blackperl.Perl.Lcfirst;
 
     String name = "PmOdE";
     String bettername = Lcfirst.lcfirst(name.toUpperCase());
     // bettername is now "pMODE".
 
     name = "name";
     name = Lcfirst.lcfirst(name); // Effectively unchanged
 
This implementation departs slightly from the Perl model in the following way: if the parameter given is a StringBuffer rather than a String, it will modify the parameter itself, directly. The return value will still be a String object, but the StringBuffer will also have the same stringified value as the returned string:
     import com.blackperl.Perl.Lcfirst;
 
     StringBuffer name = new StringBuffer("PMODE");
     String bettername = Lcfirst.lcfirst(name);
     // bettername == name.toString() == "pMODE"
 

All components in this package provide an instance method to retrieve a singleton object which may be used to call the static methods, if the programmer prefers using an object to static invocation.

If this is the JDK 1.5 ("Tiger") edition of the package, this class is suitable for use via static import:

     import com.blackperl.Perl.Lcfirst.lcfirst;
 
     String name = "PmOdE";
     String bettername = lcfirst(name.toUpperCase());
     // bettername is now "pMODE".
 


Method Summary
static com.blackperl.Perl.Lcfirst instance()
          The instance method is used to retrieve the Lcfirst singleton that applications can use in lieu of invoking the methods statically.
static java.lang.String lcfirst(java.lang.String string)
          Take the String parameter and return a new String whose first character has been made lower-case, if the character is in fact alphabetic.
static java.lang.String lcfirst(java.lang.StringBuffer buffer)
          This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place.
static java.lang.String lcfirst(java.lang.StringBuffer buffer, java.util.Locale locale)
          This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place.
static java.lang.String lcfirst(java.lang.String string, java.util.Locale locale)
          Take the String parameter and return a new String whose first character has been made lower-case, if the character is in fact alphabetic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static com.blackperl.Perl.Lcfirst instance()
The instance method is used to retrieve the Lcfirst singleton that applications can use in lieu of invoking the methods statically.

Returns:
Singleton instance of the Chomp class

lcfirst

public static java.lang.String lcfirst(java.lang.String string)
Take the String parameter and return a new String whose first character has been made lower-case, if the character is in fact alphabetic. This uses the default locale to determine the correct way to convert to lower-case. Since the argument is immutable, it itself is not changed.

Parameters:
string - The String to convert (not changed)
Returns:
The converted value

lcfirst

public static java.lang.String lcfirst(java.lang.StringBuffer buffer)
This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place. The first character is converted to lower-case using the default locale rules (if the character is not alphabetic, it is unchanged). Returns a String copy of the converted value.

Parameters:
buffer - The StringBuffer to operate on
Returns:
A String copy of the converted value

lcfirst

public static java.lang.String lcfirst(java.lang.StringBuffer buffer,
                                       java.util.Locale locale)
This form is a slight departure from the Perl equivalent, in that it actually modifies the argument in-place. The first character is converted to lower-case using the locale rules defined in the Locale parameter (if the character is not alphabetic, it is unchanged). Returns a String copy of the converted value.

Parameters:
buffer - The StringBuffer to operate on
locale - A Locale object for lower-case rules
Returns:
A String copy of the converted value

lcfirst

public static java.lang.String lcfirst(java.lang.String string,
                                       java.util.Locale locale)
Take the String parameter and return a new String whose first character has been made lower-case, if the character is in fact alphabetic. The Locale parameter determines the correct way to convert to lower-case. Since the argument is immutable, it itself is not changed.

Parameters:
string - The String to convert (not changed)
locale - A Locale object for lower-case rules
Returns:
The converted value