Package abstrasy.pcfx

Source Code of abstrasy.pcfx.PCFx_compact

package abstrasy.pcfx;


import abstrasy.Node;
import abstrasy.PCoder;

/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
*   http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/

public class PCFx_compact extends PCFx {

    public PCFx_compact() {
    }

    /**
     * eval
     *
     * @param startAt Node
     * @return Node
     * @throws Exception
     * @todo Implémenter cette méthode abstrasy.PCFx
     */
    public Node eval(Node startAt) throws Exception {
        /*
         * forme    (compact string/list) -> string/list
         *
         */
        startAt.isGoodArgsCnt(2);
        Node arg0 = startAt.getSubNode(1, Node.TYPE_STRING | Node.TYPE_CLIST | Node.VTYPE_DELEGABLE);
       
        /*
         * Cas où (compact! objet)... Il s'agit d'une surcharge...
         */
       
        if(arg0.isDelegable())
                return Node.VDelegable.evalMethod(arg0, PCoder.getMethod(PCoder.PC_COMPACT), null);
       
        // autres
       
        long qt = arg0.getQType();
        if (qt == Node.TYPE_STRING) {
            // string
            StringBuffer sb = new StringBuffer();
            String s = arg0.getString();
            for (int i = 0; i < s.length(); i++) {
                char c = s.charAt(i);
                if (!Character.isWhitespace(c)) {
                    sb.append(c);
                }
            }
            return new Node(sb.toString());
        }
        else {
            // liste
            Node r = Node.createCList();
            for (int i = 0; i < arg0.size(); i++) {
                Node c = arg0.elementAt(i);
                int ctype = c.getType();
                if (ctype != Node.TYPE_NOTHING && !c.isQuoted())
                    r.addElement(c.secure());
            }
            return r;
        }

    }

}
TOP

Related Classes of abstrasy.pcfx.PCFx_compact

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.