Package anvil.core

Source Code of anvil.core.LangModule

/*
* $Id: LangModule.java,v 1.71 2002/09/16 08:05:02 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.core;

import java.io.IOException;
import java.io.ByteArrayOutputStream;
import java.util.Enumeration;
import java.util.Arrays;
import java.util.Comparator;
/*import java.lang.reflect.Proxy;*/
import org.apache.oro.text.regex.MatchResult;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternMatcherInput;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
import anvil.script.Type;
import anvil.script.Context;
import anvil.script.Function;
import anvil.script.StackFrame;
import anvil.server.Zone;
import anvil.core.reflect.Reflection;
import anvil.core.runtime.AnyType;
import anvil.core.runtime.AnyFunction;
import anvil.core.runtime.AnyScope;
import anvil.script.compiler.NativeNamespace;
import anvil.java.util.BindingEnumeration;
import anvil.util.Conversions;
import anvil.util.Format;

///
/// @module anvil.lang
/// Set of elementary functions and classes.
/// Entities at anvil.lang are accessible directly without a need
/// to import or use <code>anvil.lang</code> prefix.
///
public class LangModule
{

  /*public static final Any proxy(Context context, Any handler, Any[] interfaces)
  {
    Zone zone = context.address().getZone();
    ClassLoader classloader = zone.getClassLoader();
    int n = interfaces.length;
    Class[] classes = new Class[n];
    int c = 0;
    for(int i=0; i<n; i++) {
      Any candidate = interfaces[i];
      if (candidate instanceof Reflection) {
        Reflection reflection = (Reflection)candidate;
        if (reflection.getType() == Type.INTERFACE) {
          classes[c++] = reflection.getJavaClass();
        } else {
          throw context.BadParameter("Parameter #"+(2+i)+" is not java interface");
        }
      }
    }

    Object proxy = Proxy.newProxyInstance(classloader, classes,
      new AnyUtils.FunctionInvocationHandler(zone, handler));
    return Any.create(proxy);
  }*/


  /// @function canDo
  /// Checks if given tool permission exists, against
  /// current security policy
  /// @synopsis boolean canDo(String name)
  /// @synopsis boolean canDo(String name, String actions)
  public static final Object[] p_canDo = new Object[] { null, "name", "*actions", null };
  public static final Any canDo(Context context, String name, String actions)
  {
    ToolPermission tool;
    if (actions == null) {
      tool = new ToolPermission(name);
    } else {
      tool = new ToolPermission(name, actions);
    }
    return context.checkPermission(tool) ? Any.TRUE : Any.FALSE;
  }

 
  /// @function loadClass
  /// Loads the given java class or interface.
  /// @synopsis Type loadClass(String classname)
  /// @exception ClassNotFound If class couldn't be loaded
  public static final Object[] p_loadClass = new Object[] { null, "classname" };
  public static final Any loadClass(Context context, String classname)
  {
    return context.reflect(classname);
  }


  /// @function deref
  /// Returns the value referred by this given ref.
  /// @synopsis object deref(object ref)
  /// @param ref Ref to variable
  /// @param derefAll If <code>true</code>, all references are followed until
  /// first non-ref value is encountered.
  public static final Object[] p_deref = new Object[] { "ref", "*derefAll", Boolean.FALSE };
  public static final Any deref(Any ref, boolean derefAll)
  {
    if (derefAll) {
      while(ref.isRef()) {
        ref = ref.getRef();
      }
    } else {
      if (ref.isRef()) {
        ref = ref.getRef();
      }
    }
    return ref;
  }


  /// @function ref
  /// Generates and returns programmable ref from given class instance.
  /// @synopsis object ref(object provider)
  /// @param impl Class having <code>_getRef</code> (and <code>_setRef</code>) methods
  public static final Object[] p_ref = new Object[] { "impl" };
  public static final Any ref(Any impl)
  {
    return new AnyClassRef(impl);
  }


  /// @function reveal
  /// Reveals and returns the ref implementation, encapsulated with <code>ref()</code>.
  /// @synopsis object reveal(object ref)
  /// @param ref Programmable ref
  public static final Object[] p_reveal = new Object[] { "ref" };
  public static final Any reveal(Any impl)
  {
    if (impl instanceof AnyClassRef) {
      return ((AnyClassRef)impl).getProvider();
    } else {
      return impl.getRef();
    }
  } 
 

  /// @function areSame
  /// Checks if two objects share the same memory address.
  /// @synopsis boolean areSame(a, b)
  public static final Any areSame(Any a, Any b)
  {
    return a == b ? Any.TRUE : Any.FALSE;
  }
 

  /// @function reduce
  /// Iterates through the given elements and calls reducer function so
  /// that the first parameter will be either the result of previous reducer
  /// call or intialValue (if it was given), and all other parameters, up to
  /// count are taken from then elements.
  /// @synopsis object reduce(object reducer, object elements)
  /// @synopsis object reduce(object reducer, int count, object elements)
  /// @synopsis object reduce(object reducer, int count, object initialValue, object elements)
  /// @param reducer Callable reducer taking from count parameters
  /// @param count number of parameters to pass to reducer, default is two.
  /// @param intialValue initial value of reduction
  /// @return the return value of last call to reducer or initialValue
  public static final Object[] p_reduce = {"<context>", "reducer", "data1", "*data2", null, "*data2", null };
  public static final Any reduce(Context context, Any reducer, Any data1, Any data2, Any data3)
  {
    int count = 2;
    Any elements;
    Any rv = null;
    if (data2 != null) {
      count = data1.toInt();
      if (data3 != null) {
        rv = data2;
        elements = data3;
      } else {
        elements = data2;
      }
    } else {
      elements = data1;
    }
    if (count < 2) {
      throw context.BadParameter("count must be >= 2");
    }
    Enumeration e = elements.enumeration();
    Any[] params = new Any[count];
    out: while(e.hasMoreElements()) {
      int c = 0;
      if (rv != null) {
        params[c++] = rv;
      }
      while(c<count) {
        if (e.hasMoreElements()) {
          params[c++] = Any.create(e.nextElement());
        } else {
          Any[] newparams = new Any[c];
          if (c>0) {
            System.arraycopy(params, 0, newparams, 0, c);
            params = newparams;
            break;
          } else {
            break out;
          }
        }
      }
      if (c == 0) {
        return Any.UNDEFINED;
      }
      if (c == 1) {
        return params[0];
      }
      rv = reducer.execute(context, params);
    }
    return Any.create(rv);
  }
 

  /// @function join
  /// Joins the elements together with given clue.
  /// @synopsis string join(object elements)
  /// @synopsis string join(object elements, string clue)
  /// @param clue Clue to join with, default is <code>", "</code>.
  public static final Object[] p_join = new Object[] { "elements", "*clue", ", " };
  public static final Any join(Any elements, String clue)
  {
    StringBuffer buffer = new StringBuffer();
    BindingEnumeration enum = elements.enumeration();
    boolean more = enum.hasMoreElements();
    while(more) {
      buffer.append(enum.nextElement().toString());
      more = enum.hasMoreElements();
      if (more) {
        buffer.append(clue);
      }
    }
    return new AnyString(buffer.toString());
  }
 

  /// @function sort
  /// Sorts the elements of sequence with given comparator.
  /// @synopsis enumeration sort(object sorter, object elements)
  /// @synopsis enumeration sort(object sorter, object elements, object data)
  /// @param sorter Callable comparator receiving parameters <code>(value1, value2, data)</code>
  /// @param data Data passed as a third parameter to comparator.
  public static final Object[] p_sort = new Object[] { "callable", "list", "*data", Any.UNDEFINED };
  public static final Any sort(Context context, Any callable, Any list, Any data)
  {
    Comparator comparator = new AnyUtils.EnumerationComparator(context, callable, data);
    java.util.TreeSet set = new java.util.TreeSet(comparator);
    BindingEnumeration enum = list.enumeration();
    while(enum.hasMoreElements()) {
      set.add(Any.create(enum.nextElement()));
    }
    return new AnyBindingEnumeration(new AnyUtils.IteratorToEnumeration(set.iterator()));
 
 
 
  /// @function select
  /// Returns enumeration of all elements for which the
  /// given function returned <code>true</code>.
  /// @synopsis enumeration select(object selector, object elements)
  /// @synopsis enumeration select(object selector, object elements, object data)
  /// @param pipe Callable selector receiving parameters
  /// <code>(element, index, data)</code>
  /// @param data Data passed as third parameter to selector.
  public static final Object[] p_select = {"<context>", "selector", "list", "*data", Any.UNDEFINED };
  public static final Any select(Context context, Any selector, Any list, Any data)
  {
    return new AnyBindingEnumeration(new AnyUtils.SelectEnumeration(
      context, selector, list.enumeration(), data));
  }
 

  /// @function pipe
  /// Returns enumeration that iterates through given elements
  /// and pipes the return value of given function as element
  /// on call to <code>enumeration.next</code>.
  /// @synopsis enumeration pipe(object converter, object elements)
  /// @synopsis enumeration pipe(object converter, object elements, object data)
  /// @param converter Callable converter receiving parameters <code>element, index, data)</code>
  /// @param data Data passed as a third parameter to converter
  public static final Object[] p_pipe = {"<context>", "pipe", "list", "*data", Any.UNDEFINED };
  public static final Any pipe(Context context, Any pipe, Any list, Any data)
  {
    return new AnyBindingEnumeration(new AnyUtils.PipeEnumeration(
      context, pipe, list.enumeration(), data));
  }
   

  /// @function apply
  /// Iterates through given elements and applies given applier for
  /// each element.
  /// @synopsis int apply(object applier, object elements)
  /// @synopsis int apply(object applier, object elements, object data)
  /// @param applier Callable applier receiving parameters <code>(element, index, data)</code>
  /// @param data Data passed as a third parameter to applier
  /// @return Number of times applier function was called
  public static final Object[] p_apply = {"<context>", "walker", "list", "*data", Any.UNDEFINED };
  public static final Any apply(Context context, Any walker, Any list, Any data)
  {
    Any[] params = new Any[3];
    params[2] = data;
    int count = 0;
    BindingEnumeration enum = list.enumeration();
    while(enum.hasMoreElements()) {
      count++;
      Any key = Any.create(enum.nextKey());
      Any value = Any.create(enum.nextElement());
      params[0] = value;
      params[1] = key;
      if (!walker.execute(context, params).toBoolean()) {
        break;
      }
    }
    return Any.create(count);
  }
       

  /// @function toLower
  /// Converts given parameter to lower case.
  /// @synopsis string toLower(string str)
  public static final Any toLower(String str)
  {
    return Any.create(str.toLowerCase());
  }
  

  /// @function toLower
  /// Converts given parameter to upper case.
  /// @synopsis string toUpper(string str)
  public static final Any toUpper(String str)
  {
    return Any.create(str.toUpperCase());
  }
  
 

  /// @function serialize
  /// Serializes data.
  /// @synopsis string serialize(object data)
  /// @return Data serialized to string representation.
  public static final Any serialize(Context context, Any value)
  {
    try {
      return new AnyString(Serialization.serialize(context, value));
    } catch (IOException e) {
      throw context.exception(e);
    }
  }
 

  /// @function bserialize
  /// Serializes data.
  /// @synopsis binary serialize(object data)
  /// @return Data serialized to binary.
  public static final Any bserialize(Context context, Any value)
  {
    try {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      Serialization.serialize(context, value, out);
      return new AnyBinary(out.toByteArray());
    } catch (IOException e) {
      throw context.exception(e);
    }
  }
 

  /// @function unserialize
  /// Unserializes data representation.
  /// @synopsis object unserialize(string repr)
  /// @synopsis object unserialize(binary repr)
  public static final Any unserialize(Context context, Any value)
  {
    try {
      if (value.isString()) {
        return Serialization.unserialize(context, value.toString());
      } else if (value.isBinary()) {
        return Serialization.unserialize(context, value.toBinary(), 0, value.sizeOf());
      }
    } catch (UnserializationException e) {
      e.printStackTrace();
      throw context.CorruptedSerialization();
    }
    return Any.UNDEFINED;
  }


  /// @function addressOf
  /// Returns memory address of parameters. Returned value for
  /// same value is not guaranteed to be same between calls.
  /// @synopsis int addressOf(object data)
  public static Any addressOf(Any value)
  {
    return Any.create(System.identityHashCode(value));
  }
 

  /// @function chr
  /// Converts given character code into character (to string
  /// which has the length of one).
  /// @synopsis string chr(int code)
  public static final Object[] p_chr = { "code" };
  public static final Any chr(int code)
  {
    return Any.create((char)code);
  }


  /// @function ord
  /// Converts first character of given string to its
  /// ordinal value.
  /// @synopsis int ord(string str)
  public static final Object[] p_ord = { "str" };
  public static final Any ord(String value)
  {
    return value.length() > 0 ? Any.create((int)value.charAt(0)) : Any.ZERO;
  }
 


  /// @function parseNumber
  /// Attempts to parse given string to integer. Valid formats are
  /// 123 (decimal), 0x123 (hex) , 0b101 (binary) , 0123 (octal)
  /// @synopsis parseNumber(string str)
  /// @synopsis parseNumber(string str, int defaultValue)
  /// @param str String to convert
  /// @param defaultValue Value returned if parsing failed, by default null.
  /// @return Integer parsed.
  public static final Object[] p_parseNumber = { "str", "*defaultValue", Any.NULL };
  public static final Any parseNumber(String value, Any defaultValue)
  {
    try {
      return Any.create(Conversions.parseNumberUnsafe(value));
    } catch (NumberFormatException e) {
      return defaultValue;
    }
  }


  /// @function parseInt
  /// Attempts to parse given string to integer.
  /// @synopsis parseInt(string str)
  /// @synopsis parseInt(string str, int radix)
  /// @synopsis parseInt(string str, int radix, int defaultValue)
  /// @param str String to convert
  /// @param radix Radix of string, default is 10.
  /// @param defaultValue Value returned if parsing failed, by default null.
  /// @return Parsed integer.
  public static final Object[] p_parseInt = { "str", "*radix", new Integer(10), "*defaultValue", Any.NULL };
  public static final Any parseInt(String value, int radix, Any defaultValue)
  {
    if (radix < Character.MIN_RADIX) {
      radix = 10;
    } else if (radix > Character.MAX_RADIX) {
      radix = 10;
    }
    try {
      return Any.create(Long.parseLong(value, radix));
    } catch (NumberFormatException e) {
      return defaultValue;
    }
  }


  /// @function parseFloat
  /// Attempts to parse given string to float.
  /// @synopsis parseFloat(string str)
  /// @synopsis parseFloat(string str, float defaultValue)
  /// @param str String to convert
  /// @param defaultValue Value returned if parsing failed, by default null.
  /// @return Parsed float.
  public static final Object[] p_parseFloat = { "str", "*defaultValue", Any.NULL };
  public static final Any parseFloat(String value, Any defaultValue)
  {
    try {
      return Any.create(Double.parseDouble(value));
    } catch (NumberFormatException e) {
      return defaultValue;
    }
  }


  /// @function createArray
  /// Creates multidimensional rectangular array with given dimensions.
  /// @synopsis createArray(range dimensions...)
  /// @param dimension Integer for upper bound or list as (lobound, hibound).
  /// @return Array created
  public static final Object[] p_createArray = { new Integer(1), "dimensions" };
  public static final Any createArray(Any[] parameters)
  {
    int max = (parameters != null) ? parameters.length : 0;
    if (max < 1) {
      return Any.NULL;
    }
    return createArray(null, parameters, 0);
  }


  /// @function createMatrix
  /// Creates multidimensional rectangular array with default values.
  /// @synopsis createMatrix(range dimensions...)
  /// @param defaultValue Default value for each leaf element.
  /// @param dimension Integer for upper bound or list as (lobound, hibound).
  /// @return Array created
  public static final Object[] p_createMatrix = { new Integer(2), "initialValue", "dimensions" };
  public static final Any createMatrix(Any initialValue, Any[] parameters)
  {
    int max = (parameters != null) ? parameters.length : 0;
    if (max < 1) {
      return Any.NULL;
    }
    return createArray(initialValue, parameters, 0);
  }


  private static final Any createArray(Any initialValue, Any[] ranges, int level)
  {
    if (level >= ranges.length) {
      return initialValue;
    }
   
    Any range = ranges[level];
    int start = 0;
    int end = 0;
    if (range.isRange()) {
      AnyRange r = range.toRange();
      start = r.getLeft().toInt();
      end = r.getRight().toInt();
    } else {
      end = range.toInt() - 1;
    }
   
    if (start <= end) {
      Array array = new Array(end-start);
      Any value;
      while(start <= end) {
        value = createArray(initialValue, ranges, level+1);
        if (value == null) {
          value = new Array();
        }
        array.append(new AnyInt(start), value);
        start++;
      }
      return array;
    } else {
      return new Array();
    }
  }


  /// @function or
  /// Returns the result of binary arithmetic OR.
  /// @synopsis int or(object a, int b, ...);
  /// @return Result of binary OR.
  public static final Object[] p_or = { new Integer(2), "a", "b", "rest" };
  public static final Any or(long a, long b, Any[] rest)
  {
    long r = a | b;
    final int n = rest.length;
    if (n > 0) {
      for(int i=0; i<n; i++) {
        r = r | rest[i].toLong();
      }
    }
    return Any.create(r);
  }


  /// @function and
  /// Returns the result of binary arithmetic AND.
  /// @synopsis int and(int a, int b, ...);
  /// @return Result of binary AND.
  public static final Object[] p_and = { new Integer(2), "a", "b", "rest" };
  public static final Any and(long a, long b, Any[] rest)
  {
    long r = a & b;
    final int n = rest.length;
    if (n > 0) {
      for(int i=0; i<n; i++) {
        r = r & rest[i].toLong();
      }
    }
    return Any.create(r);
  }


  /// @function xor
  /// Returns the result of logical xor.
  /// @synopsis xor(object a, object b, ...);
  /// @return Result of logical xor.
  public static final Object[] p_xor = { new Integer(2), "a", "b", "rest" };
  public static final Any xor(long a, long b, Any[] rest)
  {
    long r = a ^ b;
    final int n = rest.length;
    if (n > 0) {
      for(int i=0; i<n; i++) {
        r = r ^ rest[i].toLong();
      }
    }
    return Any.create(r);
  }


  /// @function neg
  /// Returns the result of logical negation.
  /// @synopsis int neg(int a)
  /// @return Result of logical negation.
  public static final Object[] p_neg = { "a" };
  public static final Any neg(long a)
  {
    return Any.create(~a);
  }


  /// @function shift
  /// Shifts the parameter to left or right for given amount.
  /// @synopsis int shift(int a, int amount)
  /// @param amount Left shift if positive, right shift if negative.
  /// @return Result of shift.
  public static final Object[] p_shift = { "a", "amount" };
  public static final Any shift(long a, int amount)
  {
    if (amount < 0) {
      return Any.create(a >> -amount);
    } else {
      return Any.create(a << amount);
    }
  }


  private static final void appendHrefTo(StringBuffer buffer, Any value, boolean isAlone)
  {
    if (isAlone && (buffer.length()>0)) {
      buffer.append('&');
    }
    switch(value.typeOf()) {
    case Any.IS_NULL:
    case Any.IS_UNDEFINED:
      break;
         
    case Any.IS_BOOLEAN:
    case Any.IS_INT:
    case Any.IS_DOUBLE:
      buffer.append(value.toString());
      if (isAlone) {
        buffer.append('=');
      }
      break;
     
    case Any.IS_STRING:
      buffer.append(Conversions.URLEncode(value.toString()));
      if (isAlone) {
        buffer.append('=');
      }
      break;

    case Any.IS_MAP:
      AnyMap map = value.toMap();
      buffer.append(Conversions.URLEncode(map.getLeft().toString()));
      buffer.append('=');
      buffer.append(Conversions.URLEncode(map.getRight().toString()));
      break;

    case Any.IS_TUPLE:
    case Any.IS_LIST:
    case Any.IS_ARRAY:
      if (isAlone) {
        BindingEnumeration enum = value.enumeration();
        Any key;
        while(enum.hasMoreElements()) {
          key = (Any)enum.nextKey();
          if (!key.isInt()) {
            buffer.append(Conversions.URLEncode(key.toString()));
            buffer.append('=');
          }
          appendHrefTo(buffer, (Any)enum.nextElement(), false);
          if (enum.hasMoreElements()) {
            buffer.append('&');
          }
        }
      }
      break;
   
    default:
      buffer.append(Conversions.URLEncode(value.toString()));
      if (isAlone) {
        buffer.append('=');
      }
      break;
    }
  }
 

  /// @function toHref
  /// Creates query string.
  /// @synopsis toHref(param, ...)
  /// @param param Map <code>key=>value</code> for mapped values,
  /// array or sequence of values or anything else for mappings with empty value.
  /// @return Query string
  public static final Object[] p_toHref = { "p1", "*p2", null, "rest" }
  public static final Any toHref(Any p1, Any p2, Any[] rest)
  {
    StringBuffer href = new StringBuffer();
    appendHrefTo(href, p1, true);
    if (p2 != null) {
      appendHrefTo(href, p2, true);
      if (rest != null) {
        int n = rest.length;
        for(int i=0; i<n; i++) {
          appendHrefTo(href, rest[i], true);
        }
      }
    }
    return new AnyString(href.toString());
  }


  /// @function format
  /// Format 'sprintf' style format string with given parameters. Format
  /// may contain fields:
  /// <br><br>
  /// <table border=1>
  /// <tr><td colspan=2>
  ///   <tt>% [-]? [+]? [0]? [width] ( [.] [precision] ) [csdifg]</tt>
  /// </td></tr>
  /// <tr><td>-</td><td>
  ///   Adjust left, instead of right.
  /// </td>
  /// <tr><td>+</td><td>Numbers with sign</td>
  /// <tr><td>0</td><td>Pad numbers with zeros, instead of spaces</td>
  /// <tr><td>width</td><td>Width of field, if '*' width will be taken from arguments</td>
  /// <tr><td>precision</td><td>Width of fraction part (doubles), if '*' width will be
  ///   taken from arguments</td>
  /// <tr><td>c</td><td>
  ///   Character (integer or first character from string).
  /// </td>
  /// <tr><td>s</td><td>String</td>
  /// <tr><td>d,i</td><td>Integer</td>
  /// <tr><td>f</td><td>
  ///   Float, follows width.precision stricly
  /// </td>
  /// <tr><td>g</td><td>
  ///   Float with signicant fraction shown, if precision is zero (or not given)
  ///   shows significant digits from it.
  /// </td>
  /// </table>
  ///
  /// Use %% to escape %.<br>
  /// @synopsis format(string format, ...)
  /// @param format Format string
  /// @return Formatted string
  public static final Object[] p_format = { "format", "parameters" };
  public static final Any format(String format, Any[] arguments)
  {
    return Any.create(anvil.util.Format.format(format, arguments));
  }


  /// @function escape
  /// Converts string to backslash escaped format.
  /// @synopsis string escape(string str)
  /// @param str String to escape
  /// @return Escaped string
  public static final Object[] p_escape = { "str" };
  public static final Any escape(String str)
  {
    return Any.create(anvil.util.Conversions.escape(str));
  }


  /// @function quote
  /// Converts all applicable characters in string to html-entities.
  /// @synopsis string quote(string str)
  /// @param str String to quote
  /// @return Quoted string
  public static final Object[] p_quote = { "str" };
  public static final Any quote(String str)
  {
    return Any.create(anvil.util.Conversions.encodeEntities(str));
  }


  /// @function unquote
  /// Converts all applicable &quot;entities; to their character counterparts.
  /// @synopsis string unquote(string str)
  /// @param str String to unquote
  /// @return Unquoted string
  public static final Object[] p_unquote = { "str" };
  public static final Any unquote(String str)
  {
    return Any.create(anvil.util.Conversions.decodeEntities(str));
  }


  /// @function encode Encodes string.
  /// @synopsis string encode(string str)
  /// @param str String
  /// @return Encoded string
  public static final Object[] p_encode = { "str" };
  public static final Any encode(String str)
  {
    return Any.create(anvil.util.Conversions.URLEncode(str));
  }


  /// @function decode Decodes URL encoded string.
  /// @synopsis string decode(string str)
  /// @param str URL encoded string
  /// @return Decoded string
  public static final Object[] p_decode = { "str" };
  public static final Any decode(String str)
  {
    return Any.create(anvil.util.Conversions.URLDecode(str));
  }


  private static Any SUFFIX_TH = Any.create("th");
  private static Any SUFFIX_ST = Any.create("st");
  private static Any SUFFIX_ND = Any.create("nd");
  private static Any SUFFIX_RD = Any.create("rd");


  /// @function th
  /// Returns english numeral suffix (st, nd, th) for given value.
  /// @synopsis string th(int number)
  /// @param value
  /// @return Numeral suffix.
  public static final Object[] p_th = { "value" };
  public static final Any th(int i)
  {
    if ((i>=11) && (i<=13)) {
      return SUFFIX_TH;
    } else {
      switch(i % 10) {
      case 1:
        return SUFFIX_ST;
      case 2:
        return SUFFIX_ND;
      case 3:
        return SUFFIX_RD;
      default:
        return SUFFIX_TH;
      }
    }
  }

 
  /// @function clone
  /// Creates shallow copy from given value.
  /// @synopsis object clone(object value)
  /// @param value Value to be cloned.
  /// @return Cloned value
  public static final Object[] p_clone = { null, "value" };
  public static final Any clone(Context context, Any value)
  {
    return (Any)value.clone();
  }
 

  /// @function copy
  /// Creates deep copy from 'value'.
  /// @synopsis object copy(object value)
  /// @param value Value to be copied.
  /// @return Copied value
  public static final Object[] p_copy = { null, "value" };
  public static final Any copy(Context context, Any value)
  {
    return value.copy();
  }



  /// @function coerce
  /// Returns list containing 'a' and 'b' converted
  /// to similar types according to same rules
  /// applied to arithmetic operations.
  /// If second parameter is omitted tries to convert
  /// string to int or float, if conversion fails
  /// returns self.
  /// @synopsis tuple coerce(object a, object b)
  /// @synopsis object coerce(object a)
  public static final Object[] p_coerce = { "a", "*b", null };
  public static final Any coerce(Any a, Any b)
  {
    if (b == null) {
      return a.coerce();
    }
    int typeOfA = a.typeOf();
    int typeOfB = b.typeOf();
    if (typeOfA == Any.IS_DOUBLE || typeOfB == Any.IS_DOUBLE) {
      return new AnyTuple(new Any[] { a.toAnyDouble(), b.toAnyDouble() } );
    } else {
      return new AnyTuple(new Any[] { a.toAnyInt(), b.toAnyInt() } );
    }
  }
  /// @function divmod
  /// Performs division operation with parameters and
  /// returns result of division and remainder.
  /// @synopsis list divmod(object a, object b)
  /// @return List (divisionResult, remainder)
  public static final Object[] p_divmod = { "a", "b" };
  public static final Any divmod(Any a, Any b)
  {
    int typeOfA = a.typeOf();
    int typeOfB = b.typeOf();
    if (typeOfA == Any.IS_DOUBLE || typeOfB == Any.IS_DOUBLE) {
      double da = a.toDouble();
      double db = b.toDouble();
      return new AnyTuple(new Any[] { new AnyDouble(da/db), new AnyDouble(Math.IEEEremainder(da, db)) } );
    } else {
      int ia = a.toInt();
      int ib = b.toInt();
      if (ib == 0) {
        return new AnyTuple(new Any[] { Any.ZERO, Any.ZERO } );
      } else {
        return new AnyTuple(new Any[] { Any.create(ia/ib), Any.create(ia%ib) } );
      }
    }
  }
 
  /// @function test
  /// Compares parameters.
  /// @synopsis int test(object a, object b)
  /// @return -1 if a<b, 0 if a==b, 1 if a>b.
  public static final Object[] p_test = { "a", "b" };
  public static final Any test(Any a, Any b)
  {
    return Any.create(Any.Op.test(a,b));
 
 

  /// @function compareTo
  /// Compares parameters.
  /// @synopsis int compareTo(object a, object b)
  /// @return -1 if a<b, 0 if a==b, 1 if a>b.
  public static final Object[] p_compareTo = { "a", "b" };
  public static final Any compareTo(Any a, Any b)
  {
    return Any.create(a.compareTo(b));
  }


  /// @function equals
  /// Compares parameters.
  /// @synopsis boolean equals(object a, object b)
  /// @return true if a==b, false otherwise.
  public static final Object[] p_equals = { "a", "b" };
  public static final Any equals(Any a, Any b)
  {
    return a.equals(b) ? Any.TRUE : Any.FALSE;
  }

 

  /// @function toHex
  /// Converts number to hexadecimal format.
  /// @synopsis string toHex(int number)
  /// @synopsis string toHex(int number, int length)
  /// @synopsis string toHex(int number, int length, string pad)
  /// @param number Number to convert
  /// @param length Length of resulting string
  /// @param pad Padding character, default is '0'
  /// @return Number converted to hexadecimal
  public static final Object[] p_toHex = { "number", "*length", new Integer(0), "*pad", "0" };
  public static final Any toHex(long value, int length, String pad)
  {
    return doPad(Long.toHexString(value), length, pad);
  }


  /// @function toOctal
  /// Converts number to octal format.
  /// @synopsis string toOctal(int number)
  /// @synopsis string toOctal(int number, int length)
  /// @synopsis string toOctal(int number, int length, string pad)
  /// @param number Number to convert
  /// @param length Length of resulting string
  /// @param pad Padding character, default is '0'
  /// @return Number converted to octal
  public static final Object[] p_toOctal = { "number", "*length", new Integer(0), "*pad", "0" };
  public static final Any toOctal(long value, int length, String pad)
  {
    return doPad(Long.toOctalString(value), length, pad);
  }


  /// @function toBin
  /// Converts number to binary format.
  /// @synopsis string toBin(int number)
  /// @synopsis string toBin(int number, int length)
  /// @synopsis string toBin(int number, int length, string pad)
  /// @param number Number to convert
  /// @param length Length of resulting string
  /// @param pad Padding character, default is '0'
  /// @return Number converted to binary
  public static final Object[] p_toBin = { "number", "*length", new Integer(0), "*pad", "0" };
  public static final Any toBin(long value, int length, String pad)
  {
    return doPad(Long.toBinaryString(value), length, pad);
  }


  /// @function toRadix
  /// Converts number to given radix format.
  /// @synopsis string toRadix(int number, int radix)
  /// @synopsis string toRadix(int number, int radix, int length)
  /// @synopsis string toRadix(int number, int radix, int length, string pad)
  /// @param number Number to convert
  /// @param radix Radix
  /// @param length Length of resulting string
  /// @param pad Padding character, default is '0'
  /// @return Number converted to given radix
  public static final Object[] p_toRadix = { "number", "radix", "*length", new Integer(0), "*pad", "0" };
  public static final Any toRadix(long value, int radix, int length, String pad)
  {
    return doPad(Long.toString(value, radix), length, pad);
  }


  private static final Any doPad(String string, int length, String padstr)
  {
    if (length == 0) {
      return ObjectPool.createString(string);
    }

    char pad;
    if (padstr == null || padstr.length() == 0) {
      pad = '0';
    } else {
      pad = padstr.charAt(0);
    }

    if (length > 0) {
      int n = string.length();
      if (n < length) {
        StringBuffer buffer = new StringBuffer(length);
        while(n++ < length) {
          buffer.append(pad);
        }
        buffer.append(string);
        return ObjectPool.createString(buffer.toString());
      } else {
        return ObjectPool.createString(string);
      }
    } else {
      int n = string.length();
      length = -length;
      if (n < length) {
        StringBuffer buffer = new StringBuffer(length);
        buffer.append(string);
        while(n++ < length) {
          buffer.append(pad);
        }
        return ObjectPool.createString(buffer.toString());
      } else {
        return ObjectPool.createString(string);
      }
    }
  }


  /// @function toAnvil
  /// Converts value to valid code producing the same value.
  /// @synopsis string toAnvil(object value)
  public static final Object[] p_toAnvil = { "value" };
  public static final Any toAnvil(Any value)
  {
    return new AnyString(value.toAnvil());
  }


  /// @function toJava
  /// Converts value to valid code producing the same value.
  /// @synopsis string toJava(object value)
  public static final Object[] p_toJava = { "value" };
  public static final Any toJava(Any value)
  {
    return new AnyString(value.toJava());
  }


  /// @function toString
  /// Converts sequence to string. Useful with sequences, arrays, enumerations
  /// and any other values returning enumeration.
  /// @synopsis string toString(object value)
  public static final Object[] p_toString = { "value" };
  public static final Any toString(Any value)
  {
    int n;
    byte[] bytes;
    StringBuffer buf;
    switch(value.typeOf()) {
    case Any.IS_STRING:
      return value;
     
    case Any.IS_BUFFER:
      return value.toAnyString();
     
    case Any.IS_BINARY:
      return new AnyString(new String(value.toBinary(), 0, value.sizeOf()));
     
    case Any.IS_TUPLE:
    case Any.IS_LIST:
      Any[] list = value.toTuple();
      n = value.sizeOf();
      buf = new StringBuffer(n);
      for(int i=0; i<n; i++) {
        buf.append(list[i].toChar());
      }
      return new AnyString(buf.toString());
   
    case Any.IS_ARRAY:
      Array array = value.toArray();
      n = array.size();
      buf = new StringBuffer(n);
      Enumeration e = array.elements();
      while(e.hasMoreElements()) {
        buf.append(((Any)e.nextElement()).toChar());
      }
      return new AnyString(buf.toString());
     
    default:
      return new AnyString(value.toString());
    }
  }


  /// @function toBuffer
  /// Converts sequence to buffer. Useful with sequences, arrays, enumerations
  /// and any other values returning enumeration.
  /// @synopsis string toBuffer(object value)
  public static final Object[] p_toBuffer = { "value" };
  public static final Any toBuffer(Any value)
  {
    int n;
    byte[] bytes;
    StringBuffer buf;
    switch(value.typeOf()) {
    case Any.IS_STRING:
      return new AnyBuffer(new StringBuffer(value.toString()));
     
    case Any.IS_BUFFER:
      return value;
     
    case Any.IS_BINARY:
      return new AnyBuffer(new StringBuffer(new String(value.toBinary(), 0, value.sizeOf())));
     
    case Any.IS_TUPLE:
    case Any.IS_LIST:
      Any[] list = value.toTuple();
      n = value.sizeOf();
      buf = new StringBuffer(n);
      for(int i=0; i<n; i++) {
        buf.append(list[i].toChar());
      }
      return new AnyBuffer(buf);
   
    case Any.IS_ARRAY:
      Array array = value.toArray();
      n = array.size();
      buf = new StringBuffer(n);
      Enumeration e = array.elements();
      while(e.hasMoreElements()) {
        buf.append(((Any)e.nextElement()).toChar());
      }
      return new AnyBuffer(buf);
     
    default:
      return new AnyBuffer(new StringBuffer(value.toString()));
    }
  }



  /// @function toBinary
  /// Converts sequence to binary. Useful with sequences, arrays, enumerations
  /// and any other values returning enumeration.
  /// @synopsis binary toBinary(object value)
  public static final Object[] p_toBinary = { "value" };
  public static final Any toBinary(Any value)
  {
    int n;
    byte[] bytes;
    switch(value.typeOf()) {
    case Any.IS_STRING:
    case Any.IS_BUFFER:
      return new AnyBinary(anvil.util.Conversions.getBytes(value.toString()));
     
    case Any.IS_BINARY:
      return value;
     
    case Any.IS_TUPLE:
    case Any.IS_LIST:
      Any[] list = value.toTuple();
      n = value.sizeOf();
      bytes = new byte[n];
      for(int i=0; i<n; i++) {
        Any e = list[i];
        if (e.coerce().isString()) {
          bytes[i] = (byte)e.toChar();
        } else {
          bytes[i] = e.toByte();
        }
      }
      return new AnyBinary(bytes);
   
    case Any.IS_ARRAY:
      {
        Array array = value.toArray();
        n = array.size();
        bytes = new byte[n];
        int i = 0;
        Enumeration e = array.elements();
        while(i<n && e.hasMoreElements()) {
          bytes[i++] = (byte)((Any)e.nextElement()).toInt();
        }
        return new AnyBinary(bytes);
      }
     
    default:
      {
        AnyBinary binary = new AnyBinary();
        Enumeration e = value.enumeration();
        while(e.hasMoreElements()) {
          binary.append(Any.create(e.nextElement()));
        }
        return binary;
      }
    }
  }


  /// @function toTuple
  /// Converts sequence to binary. Useful with sequences, arrays, enumerations
  /// and any other values returning enumeration.
  /// @synopsis tuple toTuple(object value)
  public static final Object[] p_toTuple = { "value" };
  public static final Any toTuple(Any value)
  {
    Any[] list;
    int n;
   
    switch(value.typeOf()) {
    case Any.IS_STRING:
      String str = value.toString();
      n = str.length();
      if (n == 0) {
        break;
      }     
      list = new Any[n];
      for(int i=0; i<n; i++) {
        list[i] = Any.create(str.charAt(i));
      }
      return new AnyTuple(list);

    case Any.IS_BUFFER:
      StringBuffer buf = value.toBuffer();
      n = buf.length();
      if (n == 0) {
        break;
      }     
      list = new Any[n];
      for(int i=0; i<n; i++) {
        list[i] = Any.create(buf.charAt(i));
      }
      return new AnyTuple(list);
     
    case Any.IS_TUPLE:
      return value;
     
    case Any.IS_LIST:
      list = value.toList();
      n = value.sizeOf();
      if (n == 0) {
        break;
      }     
      Any[] newlist = new Any[n];
      System.arraycopy(list, 0, newlist, 0, n);
      return new AnyList(newlist);
     
    case Any.IS_BINARY:
      byte[] bytes = value.toBinary();
      n = value.sizeOf();
      if (n == 0) {
        break;
      }
      list = new Any[n];
      for(int i=0; i<n; i++) {
        list[i] = Any.create(bytes[i]);
      }
      return new AnyTuple(list);
   
    case Any.IS_ARRAY:
      {
        Array array = value.toArray();
        n = array.size();
        if (n == 0) {
          break;
        }
        list = new Any[n];
        Enumeration e = array.elements();
        int i = 0;
        while(i<n && e.hasMoreElements()) {
          list[i++] = (Any)e.nextElement();
        }
        return new AnyTuple(list);
      }
     
    default:
      {
        AnyTuple tuple = new AnyTuple();
        Enumeration e = value.enumeration();
        while(e.hasMoreElements()) {
          tuple = (AnyTuple)tuple.append(Any.create(e.nextElement()));
        }
        return tuple;
      }
    }
    return Any.EMPTY_TUPLE;
  }



  /// @function toList
  /// Converts value to binary. Useful with sequences, arrays, enumerations
  /// and any other values returning enumeration.
  /// @synopsis list toList(object value)
  public static final Object[] p_toList = { "value" };
  public static final Any toList(Any value)
  {
    Any[] list;
    int n;
    switch(value.typeOf()) {
    case Any.IS_STRING:
      String str = value.toString();
      n = str.length();
      list = new Any[n];
      for(int i=0; i<n; i++) {
        list[i] = Any.create(str.charAt(i));
      }
      return new AnyList(list);

    case Any.IS_BUFFER:
      StringBuffer buf = value.toBuffer();
      n = buf.length();
      list = new Any[n];
      for(int i=0; i<n; i++) {
        list[i] = Any.create(buf.charAt(i));
      }
      return new AnyList(list);
     
    case Any.IS_TUPLE:
      list = value.toList();
      n = value.sizeOf();
      Any[] newlist = new Any[n];
      System.arraycopy(list, 0, newlist, 0, n);
      return new AnyList(newlist);

    case Any.IS_LIST:
      return value;
     
    case Any.IS_BINARY:
      byte[] bytes = value.toBinary();
      n = value.sizeOf();
      list = new Any[n];
      for(int i=0; i<n; i++) {
        list[i] = Any.create(bytes[i]);
      }
      return new AnyList(list);
   
    case Any.IS_ARRAY:
      {
        Array array = value.toArray();
        n = array.size();
        list = new Any[n];
        Enumeration e = array.elements();
        int i = 0;
        while(i<n && e.hasMoreElements()) {
          list[i++] = (Any)e.nextElement();
        }
        return new AnyList(list);
      }
     
    default:
      {
        AnyList anylist = new AnyList();
        Enumeration e = value.enumeration();
        while(e.hasMoreElements()) {
          anylist.append(Any.create(e.nextElement()));
        }
        return anylist;
      }
    }
  }



  /// @function toArray
  /// Converts value to array. Useful with sequences, arrays, enumerations
  /// and any other values returning enumeration.
  /// @synopsis array toArray(object value)
  public static final Object[] p_toArray = { "value" };
  public static final Any toArray(Any value)
  {
    Array array;
    int n;
    switch(value.typeOf()) {
    case Any.IS_STRING:
      String str = value.toString();
      n = str.length();
      array = new Array(n);
      for(int i=0; i<n; i++) {
        array.append(Any.create(str.charAt(i)));
      }
      return array;

    case Any.IS_BUFFER:
      StringBuffer buf = value.toBuffer();
      n = buf.length();
      array = new Array(n);
      for(int i=0; i<n; i++) {
        array.append(Any.create(buf.charAt(i)));
      }
      return array;
     
   case Any.IS_BINARY:
      byte[] bytes = value.toBinary();
      n = value.sizeOf();
      array = new Array(n);
      for(int i=0; i<n; i++) {
        array.append(Any.create(bytes[i]));
      }
      return array;

    case Any.IS_TUPLE:
    case Any.IS_LIST:
      Any[] list = value.toTuple();
      n = value.sizeOf();
      array = new Array(n);
      for(int i=0; i<n; i++) {
        array.append(i, list[i]);
      }
      return array;
    case Any.IS_ARRAY:
      return value;
     
    default:
      array = new Array();
      BindingEnumeration e = value.enumeration();
      while(e.hasMoreElements()) {
        array.append(Any.create(e.nextKey()), Any.create(e.nextElement()));
      }
      return array;
    }
  }

 


  /// @function context
  /// Returns context of current custom tag.
  /// @synopsis object context()
  /// @return Current context.
  public static final Any context(Context context)
  {
    return context.frame().peek();
  }


  /// @function println
  /// Same as builtin statement <code>println</code>. Prints all
  /// parameters and newline.
  /// @synopsis void println(...)
  public static final Object[] p_println = { new Integer(0), null, "parameter" };
  public static final Any println(Context context, Any[] params)
  {
    final int n = params.length;
    for (int i=0; i<n; i++) {
      context.print(params[i]);
    }
    context.println();
    return Any.TRUE;
  }
 

  /// @function print
  /// Same as builtin statement <code>print</code>. Prints all
  /// parameters.
  /// @synopsis void print(...)
  public static final Object[] p_print = { new Integer(0), null, "parameter" };
  public static final Any print(Context context, Any[] params)
  {
    final int n = params.length;
    for (int i=0; i<n; i++) {
      context.print(params[i]);
    }
    return Any.TRUE;
  }
 

  /// @function printbr
  /// Same as builtin statement <code>printbr</code>. Prints all
  /// parameters, &ltbr;gt; and a newline.
  /// @synopsis void printbr(...)
  private static final byte[] BRLN = "<br>\n".getBytes();
  public static final Object[] p_printbr = { new Integer(0), null, "parameter" };
  public static final Any printbr(Context context, Any[] params)
  {
    final int n = params.length;
    for (int i=0; i<n; i++) {
      context.print(params[i]);
    }
    context.print(BRLN);
    return Any.TRUE;
  }
 


  public static final anvil.script.compiler.NativeNamespace __module__ =
    new anvil.script.compiler.NativeNamespace(
      "lang",
      LangModule.class,
      new String[] {
        "anvil.core.AnyBinary",
        "anvil.core.AnyBindingEnumeration",
        "anvil.core.AnyBoolean",
        "anvil.core.AnyBuffer",
        "anvil.core.Any",
        "anvil.core.AnyDouble",
        "anvil.core.AnyFalse",
        "anvil.core.AnyHashlistIterator",
        "anvil.core.AnyInfinity",
        "anvil.core.AnyInt",
        "anvil.core.AnyList",
        "anvil.core.AnyMap",
        "anvil.core.AnyNull",
        "anvil.core.AnyNumber",
        "anvil.core.AnyPattern",
        "anvil.core.AnyRange",
        "anvil.core.AnySequence",
        "anvil.core.AnyString",
        "anvil.core.AnyThrowable",
        "anvil.core.AnyTrue",
        "anvil.core.AnyTuple",
        "anvil.core.AnyUndefined",
        "anvil.core.Array",
       
        "anvil.core.Throwables$TypeError",
        "anvil.core.Throwables$TypeError$BadParameter",
        "anvil.core.Throwables$TypeError$NotEnoughParameters",
        "anvil.core.Throwables$TypeError$NoSuchMethod",
        "anvil.core.Throwables$TypeError$NoSuchMember",
        "anvil.core.Throwables$TypeError$NoSuchFunction",
        "anvil.core.Throwables$TypeError$NoSuchClass",
        "anvil.core.Throwables$TypeError$NoSuchEntity",
        "anvil.core.Throwables$TypeError$NoInstance",
        "anvil.core.Throwables$TypeError$InstantiationError",
        "anvil.core.Throwables$TypeError$AttributeError",
        "anvil.core.Throwables$TypeError$ReferenceError",
        "anvil.core.Throwables$TypeError$CallError",
       
        "anvil.core.Throwables$JavaError",
        "anvil.core.Throwables$BadState",
        "anvil.core.Throwables$AssertFailed",
        "anvil.core.Throwables$CorruptedSerialization",
        "anvil.core.Throwables$MalformedPattern",
        "anvil.core.Throwables$AcquireError",
        "anvil.core.Throwables$XMLError",
        "anvil.core.Throwables$ImportError",
        "anvil.core.Throwables$AccessDenied",
        "anvil.core.Throwables$ClassNotFound",
        "anvil.core.Throwables$InternalError",
        "anvil.core.Throwables$Interrupted",
        "anvil.core.Throwables$OperationFailed",

      },
      //DOC{{
    ""+
      "\n" +
      " @module anvil.lang\n" +
      " Set of elementary functions and classes.\n" +
      " Entities at anvil.lang are accessible directly without a need\n" +
      " to import or use <code>anvil.lang</code> prefix.\n" +
      "\n" +
      " @function canDo\n" +
      " Checks if given tool permission exists, against\n" +
      " current security policy\n" +
      " @synopsis boolean canDo(String name)\n" +
      " @synopsis boolean canDo(String name, String actions)\n" +
      " @function loadClass\n" +
      " Loads the given java class or interface.\n" +
      " @synopsis Type loadClass(String classname)\n" +
      " @exception ClassNotFound If class couldn't be loaded\n" +
      " @function deref\n" +
      " Returns the value referred by this given ref.\n" +
      " @synopsis object deref(object ref)\n" +
      " @param ref Ref to variable\n" +
      " @param derefAll If <code>true</code>, all references are followed until\n" +
      " first non-ref value is encountered.\n" +
      " @function ref\n" +
      " Generates and returns programmable ref from given class instance.\n" +
      " @synopsis object ref(object provider)\n" +
      " @param impl Class having <code>_getRef</code> (and <code>_setRef</code>) methods\n" +
      " @function reveal\n" +
      " Reveals and returns the ref implementation, encapsulated with <code>ref()</code>.\n" +
      " @synopsis object reveal(object ref)\n" +
      " @param ref Programmable ref\n" +
      " @function areSame\n" +
      " Checks if two objects share the same memory address.\n" +
      " @synopsis boolean areSame(a, b)\n" +
      " @function reduce\n" +
      " Iterates through the given elements and calls reducer function so \n" +
      " that the first parameter will be either the result of previous reducer\n" +
      " call or intialValue (if it was given), and all other parameters, up to\n" +
      " count are taken from then elements. \n" +
      " @synopsis object reduce(object reducer, object elements)\n" +
      " @synopsis object reduce(object reducer, int count, object elements)\n" +
      " @synopsis object reduce(object reducer, int count, object initialValue, object elements)\n" +
      " @param reducer Callable reducer taking from count parameters\n" +
      " @param count number of parameters to pass to reducer, default is two.\n" +
      " @param intialValue initial value of reduction\n" +
      " @return the return value of last call to reducer or initialValue\n" +
      " @function join\n" +
      " Joins the elements together with given clue.\n" +
      " @synopsis string join(object elements)\n" +
      " @synopsis string join(object elements, string clue)\n" +
      " @param clue Clue to join with, default is <code>\", \"</code>.\n" +
      " @function sort\n" +
      " Sorts the elements of sequence with given comparator.\n" +
      " @synopsis enumeration sort(object sorter, object elements)\n" +
      " @synopsis enumeration sort(object sorter, object elements, object data)\n" +
      " @param sorter Callable comparator receiving parameters <code>(value1, value2, data)</code>\n" +
      " @param data Data passed as a third parameter to comparator.\n" +
      " @function select\n" +
      " Returns enumeration of all elements for which the\n" +
      " given function returned <code>true</code>. \n" +
      " @synopsis enumeration select(object selector, object elements)\n" +
      " @synopsis enumeration select(object selector, object elements, object data)\n" +
      " @param pipe Callable selector receiving parameters\n" +
      " <code>(element, index, data)</code>\n" +
      " @param data Data passed as third parameter to selector.\n" +
      " @function pipe\n" +
      " Returns enumeration that iterates through given elements\n" +
      " and pipes the return value of given function as element\n" +
      " on call to <code>enumeration.next</code>.\n" +
      " @synopsis enumeration pipe(object converter, object elements)\n" +
      " @synopsis enumeration pipe(object converter, object elements, object data)\n" +
      " @param converter Callable converter receiving parameters <code>element, index, data)</code>\n" +
      " @param data Data passed as a third parameter to converter\n" +
      " @function apply\n" +
      " Iterates through given elements and applies given applier for\n" +
      " each element.\n" +
      " @synopsis int apply(object applier, object elements)\n" +
      " @synopsis int apply(object applier, object elements, object data)\n" +
      " @param applier Callable applier receiving parameters <code>(element, index, data)</code>\n" +
      " @param data Data passed as a third parameter to applier\n" +
      " @return Number of times applier function was called\n" +
      " @function toLower\n" +
      " Converts given parameter to lower case.\n" +
      " @synopsis string toLower(string str)\n" +
      " @function toLower\n" +
      " Converts given parameter to upper case.\n" +
      " @synopsis string toUpper(string str)\n" +
      " @function serialize\n" +
      " Serializes data.\n" +
      " @synopsis string serialize(object data)\n" +
      " @return Data serialized to string representation.\n" +
      " @function bserialize\n" +
      " Serializes data.\n" +
      " @synopsis binary serialize(object data)\n" +
      " @return Data serialized to binary.\n" +
      " @function unserialize\n" +
      " Unserializes data representation.\n" +
      " @synopsis object unserialize(string repr)\n" +
      " @synopsis object unserialize(binary repr)\n" +
      " @function addressOf\n" +
      " Returns memory address of parameters. Returned value for\n" +
      " same value is not guaranteed to be same between calls.\n" +
      " @synopsis int addressOf(object data)\n" +
      " @function chr\n" +
      " Converts given character code into character (to string\n" +
      " which has the length of one).\n" +
      " @synopsis string chr(int code)\n" +
      " @function ord\n" +
      " Converts first character of given string to its \n" +
      " ordinal value.\n" +
      " @synopsis int ord(string str)\n" +
      " @function parseNumber\n" +
      " Attempts to parse given string to integer. Valid formats are\n" +
      " 123 (decimal), 0x123 (hex) , 0b101 (binary) , 0123 (octal)\n" +
      " @synopsis parseNumber(string str)\n" +
      " @synopsis parseNumber(string str, int defaultValue)\n" +
      " @param str String to convert\n" +
      " @param defaultValue Value returned if parsing failed, by default null.\n" +
      " @return Integer parsed.\n" +
      " @function parseInt\n" +
      " Attempts to parse given string to integer. \n" +
      " @synopsis parseInt(string str)\n" +
      " @synopsis parseInt(string str, int radix)\n" +
      " @synopsis parseInt(string str, int radix, int defaultValue)\n" +
      " @param str String to convert\n" +
      " @param radix Radix of string, default is 10.\n" +
      " @param defaultValue Value returned if parsing failed, by default null.\n" +
      " @return Parsed integer.\n" +
      " @function parseFloat\n" +
      " Attempts to parse given string to float. \n" +
      " @synopsis parseFloat(string str)\n" +
      " @synopsis parseFloat(string str, float defaultValue)\n" +
      " @param str String to convert\n" +
      " @param defaultValue Value returned if parsing failed, by default null.\n" +
      " @return Parsed float.\n" +
      " @function createArray\n" +
      " Creates multidimensional rectangular array with given dimensions.\n" +
      " @synopsis createArray(range dimensions...)\n" +
      " @param dimension Integer for upper bound or list as (lobound, hibound).\n" +
      " @return Array created\n" +
      " @function createMatrix\n" +
      " Creates multidimensional rectangular array with default values.\n" +
      " @synopsis createMatrix(range dimensions...)\n" +
      " @param defaultValue Default value for each leaf element.\n" +
      " @param dimension Integer for upper bound or list as (lobound, hibound).\n" +
      " @return Array created\n" +
      " @function or\n" +
      " Returns the result of binary arithmetic OR.\n" +
      " @synopsis int or(object a, int b, ...);\n" +
      " @return Result of binary OR.\n" +
      " @function and\n" +
      " Returns the result of binary arithmetic AND.\n" +
      " @synopsis int and(int a, int b, ...);\n" +
      " @return Result of binary AND.\n" +
      " @function xor\n" +
      " Returns the result of logical xor.\n" +
      " @synopsis xor(object a, object b, ...);\n" +
      " @return Result of logical xor.\n" +
      " @function neg\n" +
      " Returns the result of logical negation.\n" +
      " @synopsis int neg(int a)\n" +
      " @return Result of logical negation.\n" +
      " @function shift\n" +
      " Shifts the parameter to left or right for given amount.\n" +
      " @synopsis int shift(int a, int amount)\n" +
      " @param amount Left shift if positive, right shift if negative.\n" +
      " @return Result of shift.\n" +
      " @function toHref\n" +
      " Creates query string.\n" +
      " @synopsis toHref(param, ...)\n" +
      " @param param Map <code>key=>value</code> for mapped values, \n" +
      " array or sequence of values or anything else for mappings with empty value.\n" +
      " @return Query string\n" +
      " @function format\n" +
      " Format 'sprintf' style format string with given parameters. Format\n" +
      " may contain fields:\n" +
      " <br><br>\n" +
      " <table border=1>\n" +
      " <tr><td colspan=2>\n" +
      "   <tt>% [-]? [+]? [0]? [width] ( [.] [precision] ) [csdifg]</tt>\n" +
      " </td></tr>\n" +
      " <tr><td>-</td><td>\n" +
      "   Adjust left, instead of right.\n" +
      " </td>\n" +
      " <tr><td>+</td><td>Numbers with sign</td>\n" +
      " <tr><td>0</td><td>Pad numbers with zeros, instead of spaces</td>\n" +
      " <tr><td>width</td><td>Width of field, if '*' width will be taken from arguments</td>\n" +
      " <tr><td>precision</td><td>Width of fraction part (doubles), if '*' width will be\n" +
      "   taken from arguments</td>\n" +
      " <tr><td>c</td><td>\n" +
      "   Character (integer or first character from string).\n" +
      " </td>\n" +
      " <tr><td>s</td><td>String</td>\n" +
      " <tr><td>d,i</td><td>Integer</td>\n" +
      " <tr><td>f</td><td>\n" +
      "   Float, follows width.precision stricly\n" +
      " </td>\n" +
      " <tr><td>g</td><td>\n" +
      "   Float with signicant fraction shown, if precision is zero (or not given)\n" +
      "   shows significant digits from it.\n" +
      " </td>\n" +
      " </table>\n" +
      "\n" +
      " Use %% to escape %.<br>\n" +
      " @synopsis format(string format, ...)\n" +
      " @param format Format string\n" +
      " @return Formatted string\n" +
      " @function escape\n" +
      " Converts string to backslash escaped format.\n" +
      " @synopsis string escape(string str)\n" +
      " @param str String to escape\n" +
      " @return Escaped string\n" +
      " @function quote\n" +
      " Converts all applicable characters in string to html-entities.\n" +
      " @synopsis string quote(string str)\n" +
      " @param str String to quote\n" +
      " @return Quoted string\n" +
      " @function unquote\n" +
      " Converts all applicable &quot;entities; to their character counterparts.\n" +
      " @synopsis string unquote(string str)\n" +
      " @param str String to unquote\n" +
      " @return Unquoted string\n" +
      " @function encode Encodes string.\n" +
      " @synopsis string encode(string str)\n" +
      " @param str String\n" +
      " @return Encoded string\n" +
      " @function decode Decodes URL encoded string.\n" +
      " @synopsis string decode(string str)\n" +
      " @param str URL encoded string\n" +
      " @return Decoded string\n" +
      " @function th \n" +
      " Returns english numeral suffix (st, nd, th) for given value.\n" +
      " @synopsis string th(int number)\n" +
      " @param value\n" +
      " @return Numeral suffix.\n" +
      " @function clone\n" +
      " Creates shallow copy from given value.\n" +
      " @synopsis object clone(object value)\n" +
      " @param value Value to be cloned.\n" +
      " @return Cloned value\n" +
      " @function copy\n" +
      " Creates deep copy from 'value'.\n" +
      " @synopsis object copy(object value)\n" +
      " @param value Value to be copied.\n" +
      " @return Copied value\n" +
      " @function coerce\n" +
      " Returns list containing 'a' and 'b' converted\n" +
      " to similar types according to same rules\n" +
      " applied to arithmetic operations.\n" +
      " If second parameter is omitted tries to convert\n" +
      " string to int or float, if conversion fails\n" +
      " returns self.\n" +
      " @synopsis tuple coerce(object a, object b)\n" +
      " @synopsis object coerce(object a)\n" +
      " @function divmod\n" +
      " Performs division operation with parameters and\n" +
      " returns result of division and remainder.\n" +
      " @synopsis list divmod(object a, object b)\n" +
      " @return List (divisionResult, remainder)\n" +
      " @function test\n" +
      " Compares parameters.\n" +
      " @synopsis int test(object a, object b)\n" +
      " @return -1 if a<b, 0 if a==b, 1 if a>b.\n" +
      " @function compareTo\n" +
      " Compares parameters.\n" +
      " @synopsis int compareTo(object a, object b)\n" +
      " @return -1 if a<b, 0 if a==b, 1 if a>b.\n" +
      " @function equals\n" +
      " Compares parameters.\n" +
      " @synopsis boolean equals(object a, object b)\n" +
      " @return true if a==b, false otherwise.\n" +
      " @function toHex\n" +
      " Converts number to hexadecimal format.\n" +
      " @synopsis string toHex(int number)\n" +
      " @synopsis string toHex(int number, int length)\n" +
      " @synopsis string toHex(int number, int length, string pad)\n" +
      " @param number Number to convert\n" +
      " @param length Length of resulting string\n" +
      " @param pad Padding character, default is '0'\n" +
      " @return Number converted to hexadecimal\n" +
      " @function toOctal\n" +
      " Converts number to octal format.\n" +
      " @synopsis string toOctal(int number)\n" +
      " @synopsis string toOctal(int number, int length)\n" +
      " @synopsis string toOctal(int number, int length, string pad)\n" +
      " @param number Number to convert\n" +
      " @param length Length of resulting string\n" +
      " @param pad Padding character, default is '0'\n" +
      " @return Number converted to octal\n" +
      " @function toBin\n" +
      " Converts number to binary format.\n" +
      " @synopsis string toBin(int number)\n" +
      " @synopsis string toBin(int number, int length)\n" +
      " @synopsis string toBin(int number, int length, string pad)\n" +
      " @param number Number to convert\n" +
      " @param length Length of resulting string\n" +
      " @param pad Padding character, default is '0'\n" +
      " @return Number converted to binary\n" +
      " @function toRadix\n" +
      " Converts number to given radix format.\n" +
      " @synopsis string toRadix(int number, int radix)\n" +
      " @synopsis string toRadix(int number, int radix, int length)\n" +
      " @synopsis string toRadix(int number, int radix, int length, string pad)\n" +
      " @param number Number to convert\n" +
      " @param radix Radix \n" +
      " @param length Length of resulting string\n" +
      " @param pad Padding character, default is '0'\n" +
      " @return Number converted to given radix\n" +
      " @function toAnvil\n" +
      " Converts value to valid code producing the same value.\n" +
      " @synopsis string toAnvil(object value)\n" +
      " @function toJava\n" +
      " Converts value to valid code producing the same value.\n" +
      " @synopsis string toJava(object value)\n" +
      " @function toString\n" +
      " Converts sequence to string. Useful with sequences, arrays, enumerations\n" +
      " and any other values returning enumeration.\n" +
      " @synopsis string toString(object value)\n" +
      " @function toBuffer\n" +
      " Converts sequence to buffer. Useful with sequences, arrays, enumerations\n" +
      " and any other values returning enumeration.\n" +
      " @synopsis string toBuffer(object value)\n" +
      " @function toBinary\n" +
      " Converts sequence to binary. Useful with sequences, arrays, enumerations\n" +
      " and any other values returning enumeration.\n" +
      " @synopsis binary toBinary(object value)\n" +
      " @function toTuple\n" +
      " Converts sequence to binary. Useful with sequences, arrays, enumerations\n" +
      " and any other values returning enumeration.\n" +
      " @synopsis tuple toTuple(object value)\n" +
      " @function toList\n" +
      " Converts value to binary. Useful with sequences, arrays, enumerations\n" +
      " and any other values returning enumeration.\n" +
      " @synopsis list toList(object value)\n" +
      " @function toArray\n" +
      " Converts value to array. Useful with sequences, arrays, enumerations\n" +
      " and any other values returning enumeration.\n" +
      " @synopsis array toArray(object value)\n" +
      " @function context\n" +
      " Returns context of current custom tag.\n" +
      " @synopsis object context()\n" +
      " @return Current context.\n" +
      " @function println\n" +
      " Same as builtin statement <code>println</code>. Prints all\n" +
      " parameters and newline.\n" +
      " @synopsis void println(...)\n" +
      " @function print\n" +
      " Same as builtin statement <code>print</code>. Prints all\n" +
      " parameters.\n" +
      " @synopsis void print(...)\n" +
      " @function printbr\n" +
      " Same as builtin statement <code>printbr</code>. Prints all\n" +
      " parameters, &ltbr;gt; and a newline.\n" +
      " @synopsis void printbr(...)\n"
    //}}DOC
    );
 

}


TOP

Related Classes of anvil.core.LangModule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.