/**

Licence:
Copyright (c) 2013-2017 Luzzi Valerio for Gecosistema S.r.l.

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Name:       strings.java
Purpose:

Author:      Luzzi Valerio

Created:     15/02/2017

*/


/**
 *  strings - this class ...
 */
public class strings {

    /**
     * length - Returns ...
     **/
    public static String length(text){
        /*
        
    """
    lower
    """
    return len(text)

        */
        return false;
    }//end function length

    /**
     * lower - Returns ...
     **/
    public static String lower(text){
        /*
        
    """
    lower
    """
    if isinstance(text,(str,unicode)):
        return text.lower()
    elif isinstance(text,(tuple,list)):
        return [lower(item) for item in text]
    return ""

        */
        return false;
    }//end function lower

    /**
     * upper - Returns ...
     **/
    public static String upper(text){
        /*
        
    """
    upper
    """
    if isinstance(text,(str,unicode)):
        return text.upper()
    elif isinstance(text,(tuple,list)):
        return [upper(item) for item in text]
    return ""

        */
        return false;
    }//end function upper

    /**
     * isstring - Returns ...
     **/
    public static String isstring(obj){
        /*
        
    """
    isstring - Returns True if the variable is a string
    """
    return isinstance(obj,(str,unicode))

        */
        return false;
    }//end function isstring

    /**
     * isarray - Returns ...
     **/
    public static String isarray(obj){
        /*
        
    """
    isarray - Returns True if the variable is a list
    """
    return isinstance(obj,(list,tuple))

        */
        return false;
    }//end function isarray

    /**
     * isnumeric - Returns ...
     **/
    public static String isnumeric(text){
        /*
        
    """
    isnumeric - a simple implementation
    (TODO: numbers with exponent)
    """
    text = text.strip()
    dot = False
    for i in range(0,len(text)):
        c= text[i]
        if i==0 and c in "+-":
            continue
        if c =="." and not dot:
            dot= True
            continue
        if not c.isdigit():
            return False
    return True

        */
        return false;
    }//end function isnumeric

    /**
     * padr - Returns ...
     **/
    public static String padr(text,n,c){
        /*
        
    """
    padr - right pad of text with character c
    """
    text = str(text)
    return text+c * (n-len(text))

        */
        return false;
    }//end function padr

    /**
     * padl - Returns ...
     **/
    public static String padl(text,n,c){
        /*
        
    """
    left pad of text with character c
    """
    text = str(text)
    return  c * (n-len(text)) + text

        */
        return false;
    }//end function padl

    /**
     * nvl - Returns ...
     **/
    public static String nvl(value1,value2){
        /*
        
    """
    nvl - Not null value
    """
    return value2 if (value1 == None) else value1

        */
        return false;
    }//end function nvl

    /**
     * ltrim - Returns ...
     **/
    public static String ltrim(text,toremove){
        /*
        
    """
    ltrim - left trim
    """
    text = text.strip
    if isinstance(text,(str,unicode)):
        return text.lstrip(toremove)
    if isinstance(text,(list,tuple)):
        return [ltrim(item) for item in text if len(item)>0]

        */
        return false;
    }//end function ltrim

    /**
     * leftpart - Returns ...
     **/
    public static String leftpart(text,sep){
        /*
        
    """
    leftpart - returns the left part
    """
    if isinstance(text,(str,unicode)):
        arr = text.split(sep,1)
        if len(arr)>=1:
            return arr[0]
    if isinstance(text,(list,tuple)):
        return [leftpart(item,sep) for item in text]

        */
        return false;
    }//end function leftpart

    /**
     * rightpart - Returns ...
     **/
    public static String rightpart(text,sep){
        /*
        
    """
    rightpart - returns the left part
    """
    if isinstance(text,(str,unicode)):
        arr = text.split(sep,1)
        if len(arr)>1:
            return arr[1]
    if isinstance(text,(list,tuple)):
        return [rightpart(item,sep) for item in text]
    return ""

        */
        return false;
    }//end function rightpart

    /**
     * chrtran - Returns ...
     **/
    public static String chrtran(text,tosearch,toreplace){
        /*
        
    """
    chrtran - replace all characters in elenco with correspondent
    """
    for j in range(0,len(tosearch)):
        c = toreplace[j] if j in range(0,len(toreplace)) else ""
        text = text.replace(tosearch[j],c)

    return text

        */
        return false;
    }//end function chrtran

    /**
     * sformat - Returns ...
     **/
    public static String sformat(text,env){
        /*
        
    """
    sformat -
    """
    for key in env:
        text = text.replace("{%s}"%(key),"%s"%(env[key]))
    return text

        */
        return false;
    }//end function sformat

    /**
     * split - Returns ...
     **/
    public static String split(text,sep,glue,removeEmpty){
        /*
        
    """
    split - a variant of split with glue characters
    """
    res= []
    word =""
    dontsplit = False
    for j in range(0,len(text)):
        c= text[j]
        if c in glue:
            dontsplit= not dontsplit
        if c in sep and not dontsplit:
            res.append(word)
            word=""
        else:
            word+=c

    if not removeEmpty or len(word.strip())>0:
        res.append(word)

    return res

        */
        return false;
    }//end function split

    /**
     * val - Returns ...
     **/
    public static String val(text){
        /*
        
    """
    val - parse the text value
    """
    if text is None:
        return None
    if isinstance(text,int):
        return text
    if isinstance(text,float):
        return text
    #Se e' una stringa e c'e' possibilita' che sia un numero
    if isinstance(text,(str,unicode)):

        if text == "":
            return 0

        match = re.match("[-+]?(\d+(\.\d*)|\.\d+)([eE][-+]?\d+)?",text)
        if match:
            return float(match.group())
        match = re.match("[-+]?\d+",text)
        if match:
            return int(match.group())

    #Se e' una lista applico val a ogni singolo elemento
    if isinstance(text,(list,tuple)):
        return [val(item) for item in text]
    return None


if __name__ == '__main__':
    pass

        */
        return false;
    }//end function val

}//end class {classname}
