tcl.lang
Class Util

java.lang.Object
  extended by tcl.lang.Util

public class Util
extends Object


Method Summary
static void appendElement(Interp interp, StringBuffer sbuf, String s)
          appendElement -- Append a string to the string buffer.
static String checkBadOctal(Interp interp, String value)
           
static TclObject concat(int from, int to, TclObject[] objv)
          Tcl_ConcatObj -> concat Concatenate the strings from a set of objects into a single string object with spaces between the original strings.
static void convertElement(String s, int flags, StringBuffer sbuf)
          Tcl_ConvertElement -> convertElement This is a companion procedure to scanElement.
static boolean findElement(Interp interp, String s, int i, int len, tcl.lang.FindElemResult fer)
          findElement -- Given a String that contains a Tcl list, locate the first (or next) element in the list.
static int getActualPlatform()
          getActualPlatform -- This static procedure returns the integer code for the actual platform on which Jacl is running.
static boolean getBoolean(Interp interp, String string)
          getBoolean -- Given a string, return a boolean value corresponding to the string.
static double getDouble(Interp interp, String s)
          getDouble -- Converts an ASCII string to a double.
static long getInt(Interp interp, String s)
          Converts an ASCII string to an integer.
static int getIntForIndex(Interp interp, TclObject tobj, int endValue)
          TclGetIntForIndex -> Util.getIntForIndex This procedure returns an integer corresponding to the list index held in a Tcl object.
static long getWideInt(Interp interp, String str)
          Converts an ASCII string to a wide integer.
static boolean isMac()
          isMac -- Returns true if running on a Mac platform.
static boolean isUnix()
          isUnix -- Returns true if running on a Unix platform.
static boolean isWindows()
          isWindows -- Returns true if running on a Windows platform.
static boolean looksLikeInt(String s)
          looksLikeInt -- Returns true when isJacl() is true and this string looks like an integer.
static String printDouble(double number)
          printDouble -- Returns the string form of a double number.
static boolean regExpMatch(Interp interp, String string, TclObject pattern)
          regExpMatch -- See if a string matches a regular expression.
static int scanElement(Interp interp, String string)
          Tcl_ScanElement -> scanElement This procedure is a companion procedure to convertElement.
static boolean stringMatch(String str, String pat)
          stringMatch -- See if a particular string matches a particular pattern.
static void strtod(String s, int start, int len, StrtodResult strtodResult)
          strtod -- Converts the leading decimal digits of a string into double and report the index of the character immediately following the digits.
static void strtoul(String s, int start, int base, StrtoulResult strtoulResult)
          Implements functionality of the strtoul() function used in the C Tcl library.
static String toTitle(String str)
          Tcl_UtfToTitle -> toTitle -- Changes the first character of a string to title case or uppercase and the rest of the string to lowercase.
static String TrimLeft(String str)
          TrimLeft -- Trims whitespace on the left side of a strin.g Results: The trimmed string.
static String TrimLeft(String str, String pattern)
          TrimLeft -- Trim characters in "pattern" off the left of a string If pattern isn't supplied, whitespace is trimmed Results: |>None.<| Side effects: |>None.<|
static String TrimRight(String str)
           
static String TrimRight(String str, String pattern)
          TrimRight -- Trim characters in "pattern" off the right of a string If pattern isn't supplied, whitespace is trimmed Results: |>None.<|
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

strtoul

public static void strtoul(String s,
                           int start,
                           int base,
                           StrtoulResult strtoulResult)
Implements functionality of the strtoul() function used in the C Tcl library. This method will parse digits from what should be a 64-bit (signed) integer and report the index of the character immediately following the digits. E.g.: "0x7fffffff" -> 2147483647 "0x80000000" -> -2147483648 "-0xFF" -> -255 This method behaves like the strtoul() function in NativeTcl. This method will return a signed 64-bit Java long type in the strtoulResult argument. This value is used as a signed integer in the expr module. A leading signed character like '+' or '-' is supported. Leading spaces are skipped. Results: The strtoulResult argument will be populated with the parsed value and the index of the character following the digits. If an error is detected, then the strtoulResult errno value will be set accordingly. Side effects: None.

Parameters:
s - String of ASCII digits, possibly preceded by white space. For bases greater than 10, either lower- or upper-case digits may be used.
start - The index of s where the number starts.
base - Base for conversion. Must be less than 37. If 0, then the base is chosen from the leading characters of string: "0x" means hex, "0" means octal, anything else means decimal.
strtoulResult - Location to store results

getInt

public static long getInt(Interp interp,
                          String s)
                   throws TclException
Converts an ASCII string to an integer. Results: The integer value of the string. Side effects: None.

Parameters:
interp - The current interpreter. Can be null
s - The string to convert from. Must be in valid Tcl integer format.
Returns:
integer value
Throws:
TclException

getWideInt

public static long getWideInt(Interp interp,
                              String str)
                       throws TclException
Converts an ASCII string to a wide integer.

Parameters:
interp -
str -
Returns:
Throws:
TclException

getIntForIndex

public static final int getIntForIndex(Interp interp,
                                       TclObject tobj,
                                       int endValue)
                                throws TclException
TclGetIntForIndex -> Util.getIntForIndex This procedure returns an integer corresponding to the list index held in a Tcl object. The Tcl object's value is expected to be either an integer or a string of the form "end([+-]integer)?". Results: The return value is the index that is found from the string. If the Tcl object referenced by tobj has the value "end", the value stored is endValue. If tobj's value is not of the form "end([+-]integer)?" and it can not be converted to an integer, an exception is raised. Side effects: The object referenced by tobj might be converted to an integer object.

Parameters:
interp - interp, can be null
tobj - the index object, an integer, "end", or "end-n"
endValue - the index value to use as "end"
Throws:
TclException

checkBadOctal

public static final String checkBadOctal(Interp interp,
                                         String value)

strtod

public static void strtod(String s,
                          int start,
                          int len,
                          StrtodResult strtodResult)
strtod -- Converts the leading decimal digits of a string into double and report the index of the character immediately following the digits. Results: Converts the leading decimal digits of a string into double and report the index of the character immediately following the digits. Side effects: None.

Parameters:
s - String of ASCII digits, possibly preceded by white space. For bases greater than 10, either lower- or upper-case digits may be used.
start - The index of the string to start on.
len - The string length, or -1
strtodResult - place to store results

getDouble

public static double getDouble(Interp interp,
                               String s)
                        throws TclException
getDouble -- Converts an ASCII string to a double. Results: The double value of the string. Side effects: None.

Parameters:
interp - The current interpreter, can be null
s - The string to convert from. Must be in valid Tcl double format.
Returns:
the double value
Throws:
TclException

concat

public static TclObject concat(int from,
                               int to,
                               TclObject[] objv)
                        throws TclException
Tcl_ConcatObj -> concat Concatenate the strings from a set of objects into a single string object with spaces between the original strings. Results: The return value is a new string object containing a concatenation of the strings in objv. Its ref count is zero. Side effects: None.

Parameters:
from - The starting index.
to - The ending index (inclusive).
objv - Array of objects to concatenate.
Returns:
new String object
Throws:
TclException

stringMatch

public static final boolean stringMatch(String str,
                                        String pat)
stringMatch -- See if a particular string matches a particular pattern. The matching operation permits the following special characters in the pattern: *?\[] (see the manual entry for details on what these mean). Results: True if the string matches with the pattern. Side effects: None.

Parameters:
str - String to compare pattern against
pat - Pattern which may contain special characters.
Returns:
true if string matches within the pattern

toTitle

public static String toTitle(String str)
Tcl_UtfToTitle -> toTitle -- Changes the first character of a string to title case or uppercase and the rest of the string to lowercase. Results: Returns the generated string. Side effects: None.

Parameters:
str - String to convert.
Returns:
new string

regExpMatch

public static final boolean regExpMatch(Interp interp,
                                        String string,
                                        TclObject pattern)
                                 throws TclException
regExpMatch -- See if a string matches a regular expression. Results: Returns a boolean whose value depends on whether a match was made. Side effects: None.

Parameters:
interp - Current interpreter
string - The string to match.
pattern - The regular expression.
Returns:
true if matched
Throws:
TclException

appendElement

public static final void appendElement(Interp interp,
                                       StringBuffer sbuf,
                                       String s)
                                throws TclException
appendElement -- Append a string to the string buffer. If the string buffer is not empty, append a space before appending "s". Results: None. Side effects: The value of "sbuf" is changesd.

Parameters:
interp - Current interpreter.
sbuf - The buffer to append to.
s - The string to append.
Throws:
TclException

findElement

public static final boolean findElement(Interp interp,
                                        String s,
                                        int i,
                                        int len,
                                        tcl.lang.FindElemResult fer)
                                 throws TclException
findElement -- Given a String that contains a Tcl list, locate the first (or next) element in the list. Results: This method returns true and populates the FindElemResult if an element was found. If no element was found, false will be returned. The FindElemResult contains the index of the first and last characters of the element and the string value of the element. Side effects: None.

Parameters:
interp - Current interpreter, can be null.
s - The string to locate an element.
i - The index inside s to start locating an element.
len - The length of the string.
fer - The result object to populate.
Returns:
true if found.
Throws:
TclException

scanElement

public static int scanElement(Interp interp,
                              String string)
                       throws TclException
Tcl_ScanElement -> scanElement This procedure is a companion procedure to convertElement. It scans a string to see what needs to be done to it (e.g. add backslashes or enclosing braces) to make the string into a valid Tcl list element. Results: The flags needed by Tcl_ConvertElement when doing the actual conversion. Side effects: None.

Parameters:
interp - The current interpreter.
string - The String to scan. (could be null)
Returns:
flags
Throws:
TclException

convertElement

public static void convertElement(String s,
                                  int flags,
                                  StringBuffer sbuf)
Tcl_ConvertElement -> convertElement This is a companion procedure to scanElement. Given the information produced by scanElement, this procedure converts a string to a list element equal to that string. Results: Conterts a string so to a new string so that Tcl List information is not lost. Side effects: None.

Parameters:
s - Source information for list element.
flags - Flags produced by scanElement
sbuf - Buffer to write element to

TrimLeft

public static String TrimLeft(String str,
                              String pattern)
TrimLeft -- Trim characters in "pattern" off the left of a string If pattern isn't supplied, whitespace is trimmed Results: |>None.<| Side effects: |>None.<|

Parameters:
str - The string to trim
pattern - The pattern string used to trim.
Returns:
string

TrimLeft

public static String TrimLeft(String str)
TrimLeft -- Trims whitespace on the left side of a strin.g Results: The trimmed string.

Parameters:
str - The string to trim.
Returns:
The trimmed string.

TrimRight

public static String TrimRight(String str,
                               String pattern)
TrimRight -- Trim characters in "pattern" off the right of a string If pattern isn't supplied, whitespace is trimmed Results: |>None.<|

Parameters:
str - The string to trim.
pattern - The pattern to trim.
Returns:
The trimmed string.

TrimRight

public static String TrimRight(String str)

getBoolean

public static boolean getBoolean(Interp interp,
                                 String string)
                          throws TclException
getBoolean -- Given a string, return a boolean value corresponding to the string. Results: Side effects: None.

Parameters:
interp - The current interpreter.
string - The string representation of the boolean.
Returns:
boolean value of string
Throws:
TclException - For malformed boolean values.

getActualPlatform

public static final int getActualPlatform()
getActualPlatform -- This static procedure returns the integer code for the actual platform on which Jacl is running. Results: Returns and integer. Side effects: None.

Returns:
Platform int

isUnix

public static final boolean isUnix()
isUnix -- Returns true if running on a Unix platform. Results: Returns a boolean. Side effects: None.

Returns:
true if Unix

isMac

public static final boolean isMac()
isMac -- Returns true if running on a Mac platform. Note that this method returns false for Mac OSX. Results: Returns a boolean. Side effects: None.

Returns:
true if Mac

isWindows

public static final boolean isWindows()
isWindows -- Returns true if running on a Windows platform. Results: Returns a boolean. Side effects: None.

Returns:
true if Windows

looksLikeInt

public static boolean looksLikeInt(String s)
looksLikeInt -- Returns true when isJacl() is true and this string looks like an integer. Results: Returns a boolean. Side effects: None.

Parameters:
s - String to check
Returns:
true if looks like an integer

printDouble

public static String printDouble(double number)
printDouble -- Returns the string form of a double number. The exact formatting of the string depends on the tcl_precision variable. Results: Returns the string form of double number. Side effects: None.

Parameters:
number - The number to format into a string
Returns:
String rep


Copyright © 2015. All rights reserved.