All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.bliki.wiki.template.Plural Maven / Gradle / Ivy

The newest version!
package info.bliki.wiki.template;

import info.bliki.wiki.model.IWikiModel;

import java.util.List;

/**
 * A template parser function for {{plural: ... }} lower
 * case syntax. See Wikipedia -
 * Help:Variable#Formatting
 *
 */
public class Plural extends AbstractTemplateFunction {
    public final static ITemplateFunction CONST = new Plural();

    @Override
    public String parseFunction(List list, IWikiModel model, char[] src, int beginIndex, int endIndex, boolean isSubst) {
        if (list.size() > 0) {
            String arg0 = isSubst ? list.get(0) : parseTrim(list.get(0), model);
            int n = 0;
            try {
                n = Integer.parseInt(arg0, 10);
            } catch (NumberFormatException nfe) {
                // fall through?
            }
            if (list.size() > 1) {
                if (n <= 1) {
                    return isSubst ? list.get(1) : parseTrim(list.get(1), model);
                } else {
                    if (list.size() > 2) {
                        return isSubst ? list.get(2) : parseTrim(list.get(2), model);
                    }
                }
            }
            return "";
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy