Expand the URI template using the supplied values

@param vars The values that will be used in the expansion
@return the expanded URI as a String
@throw VariableExpansionException
@since 1.0
192932
public String expand(Map<String, Object> vars) throws VariableExpansionException
    {
        this.values = vars;
        return expand();
    }
1036128
private function BindExpr( $vars )
	{
		/**
		 * @var XPath2RunningContext $runningContext
		 */
		$runningContext = new XPath2RunningContext();

		/**
		 * @var ReferenceLink[] $variables
		 */
		$variables = null;
		$variableValues = null;
		if ( ! is_null( $vars ) && ! empty( $vars ) )
		{
			/**
			 * @var array[ReferenceLink] $variables
			 */
			$variables = array(); // new ReferenceLink[$vars.Count];
			$variableValues = array(); // new object[$vars.Count];
			// $array = $vars; // new KeyValuePair<QName, object>[$vars.Count];
			$array = array();
			foreach ( $vars as $key => $value )
			{
				$variables[] = $runningContext->NameBinder->PushVar( $key );
				$variableValues[] = $value;
			}
		}

		$this->context->RunningContext = $runningContext;
		$this->context->availableCollections = isset( $vars['availableCollections'] ) ? $vars['availableCollections'] : array();
		$this->context->defaultCollection = isset( $vars['defaultCollection'] ) ? $vars['defaultCollection'] : null;

		$this->exprTree->Bind();

		/**
		 * @var object[] $datapool
		 */
		$dataPool = array(); // new object[ $runningContext->NameBinder->getLength() ];
		if ( ! is_null( $variables ) )
		{
			for ( $k = 0; $k < count( $variables ); $k++ )
			{
				$variables[ $k ]->Set( $dataPool, $this->PrepareValue( $variableValues[ $k ] ) );
			}
		}
		return $dataPool;
	}
1172592
def get_expanded(self, *args, **kwargs):
        
        kwargs.setdefault("expandvars", True)
        kwargs.setdefault("expanduser", True)
        return self.get_default(*args, **kwargs)
166283
public function inflectPackageVars($vars)
    {
        $restrictedWords = implode('|', array_keys($this->locations));

        $vars['name'] = strtolower($vars['name']);
        $vars['name'] = preg_replace('/^(?:grav-)?(?:(?:'.$restrictedWords.')-)?(.*?)(?:-(?:'.$restrictedWords.'))?$/ui',
            '$1',
            $vars['name']
        );

        return $vars;
    }
1359363
public static String getVariablesMapExpression(Collection variables) {
        StringBuilder variablesMap = new StringBuilder("new  " + PropertiesMap.class.getName() + "()");
        for (Object variable : variables) {
            JRVariable jrvar = (JRVariable) variable;
            String varname = jrvar.getName();
            variablesMap.append(".with(\"").append(varname).append("\",$V{").append(varname).append("})");
        }
        return variablesMap.toString();
    }
685113
function(context) {
      var varName,
          localVars = [];
      for (varName in context) {
        localVars.push('var ' + varName + ' = context.' + varName + ';');
      }
      return localVars.join('\n');
    }
1071550
def _expand(self, str, local_vars={}):
        """"""
        return ninja_syntax.expand(str, self.vars, local_vars)
82446
public String expand(Map<String, ?> variables) {
    if (variables == null) {
      throw new IllegalArgumentException("variable map is required.");
    }

    /* resolve all expressions within the template */
    StringBuilder resolved = new StringBuilder();
    for (TemplateChunk chunk : this.templateChunks) {
      if (chunk instanceof Expression) {
        String resolvedExpression = this.resolveExpression((Expression) chunk, variables);
        if (resolvedExpression != null) {
          resolved.append(resolvedExpression);
        }
      } else {
        /* chunk is a literal value */
        resolved.append(chunk.getValue());
      }
    }
    return resolved.toString();
  }
1209020
public static List<Var> getVarsOfType(List<Var> vars, VarType type) {
        ArrayList<Var> subset = new ArrayList<Var>();
        for (Var v : vars) {
            if (v.getType() == type) {
                subset.add(v);
            }
        }
        return subset;      
    }
1172337
private String pageUri(final UriTemplate uriTemplate, final int pageNumber, final int pageSize) {
        if (pageSize == MAX_VALUE) {
            return uriTemplate.expand();
        }
        return uriTemplate.set(pageNumberVar(), pageNumber).set(pageSizeVar(), pageSize).expand();
    }
646629
public static VariablePattern fromPlate(String plateName, VariableNumMap plateVariables,
      VariableNumMap fixedVariables) {
    List<VariableNameMatcher> matchers = Lists.newArrayList();
    for (String variableName : plateVariables.getVariableNamesArray()) {
      matchers.add(new VariableNameMatcher(plateName + "/", "/" + variableName, 0));
    }
    return new VariableNamePattern(matchers, plateVariables, fixedVariables);
  }
1336252
def variables(template):
    ''''''
    vars = set()
    for varlist in TEMPLATE.findall(template):
        if varlist[0] in OPERATOR:
            varlist = varlist[1:]
        varspecs = varlist.split(',')
        for var in varspecs:
            # handle prefix values
            var = var.split(':')[0]
            # handle composite values
            if var.endswith('*'):
                var = var[:-1]
            vars.add(var)
    return vars
181731
public XStreamDOM expandMacro(VariableResolver<String> vars) {
        String[] newAttributes = new String[attributes.length];
        for (int i=0; i<attributes.length; i+=2) {
            //noinspection PointlessArithmeticExpression
            newAttributes[i+0] = attributes[i]; // name
            newAttributes[i+1] = Util.replaceMacro(attributes[i+1],vars);
        }

        List<XStreamDOM> newChildren = null;
        if (children!=null) {
            newChildren = new ArrayList<>(children.size());
            for (XStreamDOM d : children)
                newChildren.add(d.expandMacro(vars));
        }

        return new XStreamDOM(tagName,newAttributes,newChildren,Util.replaceMacro(value,vars));
    }

    public String getAttribute(String name) {
        for (int i=0; i<attributes.length; i+=2)
            if (attributes[i].equals(name))
                return attributes[i+1];
        return null;
    }

    public int getAttributeCount() {
        return attributes.length / 2;
    }

    String getAttributeName(int index) {
        return attributes[index*2];
    }

    public String getAttribute(int index) {
        return attributes[index*2+1];
    }

    public String getValue() {
        return value;
    }

    public List<XStreamDOM> getChildren() {
        return children;
    }

    /**
     * Returns a new {@link HierarchicalStreamReader} that reads a sub-tree rooted at this node.
     */
    public HierarchicalStreamReader newReader() {
        return new ReaderImpl(this);
    }

    /**
     * Returns a new {@link HierarchicalStreamWriter} for marshalling objects into {@link XStreamDOM}.
     * After the writer receives the calls, call {@link WriterImpl#getOutput()} to obtain the populated tree.
     */
    public static WriterImpl newWriter() {
        return new WriterImpl();
    }

    /**
     * Writes this {@link XStreamDOM} into {@link OutputStream}.
     */
    public void writeTo(OutputStream os) {
        writeTo(XStream2.getDefaultDriver().createWriter(os));
    }

    public void writeTo(Writer w) {
        writeTo(XStream2.getDefaultDriver().createWriter(w));
    }

    public void writeTo(HierarchicalStreamWriter w) {
        new ConverterImpl().marshal(this,w,null);
    }

    /**
     * Marshals the given object with the given XStream into {@link XStreamDOM} and return it.
     */
    public static XStreamDOM from(XStream xs, Object obj) {
        WriterImpl w = newWriter();
        xs.marshal(obj, w);
        return w.getOutput();
    }

    public static XStreamDOM from(InputStream in) {
        return from(XStream2.getDefaultDriver().createReader(in));
    }

    public static XStreamDOM from(Reader in) {
        return from(XStream2.getDefaultDriver().createReader(in));
    }

    public static XStreamDOM from(HierarchicalStreamReader in) {
        return new ConverterImpl().unmarshalElement(in, null);
    }

    public Map<String, String> getAttributeMap() {
        Map<String,String> r = new HashMap<>();
        for (int i=0; i<attributes.length; i+=2)
            r.put(attributes[i],attributes[i+1]);
        return r;
    }

    private static class ReaderImpl extends AbstractXmlReader implements DocumentReader {
        private static class Pointer {
            final XStreamDOM node;
            int pos;

            private Pointer(XStreamDOM node) {
                this.node = node;
            }

            public String peekNextChild() {
                if (hasMoreChildren())
                    return node.children.get(pos).tagName;
                return null;
            }

            public boolean hasMoreChildren() {
                return node.children!=null && pos<node.children.size();
            }

            public String xpath() {
                XStreamDOM child = node.children.get(pos - 1);
                int count =0;
                for (int i=0; i<pos-1; i++)
                    if (node.children.get(i).tagName.equals(child.tagName))
                        count++;
                boolean more = false;
                for (int i=pos; !more && i<node.children.size(); i++)
                    if (node.children.get(i).tagName.equals(child.tagName))
                        more = true;

                if (count==0 && !more)  return child.tagName;   // sole child
                return child.tagName+'['+count+']';
            }
        }

        private final Stack<Pointer> pointers = new Stack<>();


        public ReaderImpl(XStreamDOM current) {
            super(new XmlFriendlyReplacer());
            pointers.push(new Pointer(current));
        }

        private Pointer current() {
            return pointers.peek();
        }

        public Object getCurrent() {
            return current().node;
        }

        public boolean hasMoreChildren() {
            return current().hasMoreChildren();
        }

        public HierarchicalStreamReader underlyingReader() {
            return this;
        }

        public void moveDown() {
            Pointer p = current();
            pointers.push(new Pointer(p.node.children.get(p.pos++)));
        }

        public void moveUp() {
            pointers.pop();
        }

        public Iterator getAttributeNames() {
            return new AttributeNameIterator(this);
        }

        public void appendErrors(ErrorWriter errorWriter) {
            StringBuilder buf = new StringBuilder();
            Pointer parent = null;
            for (Pointer cur : pointers) {
                if (parent!=null) {
                    buf.append('/').append(parent.xpath());
                } else {
                    buf.append(cur.node.tagName);
                }
                parent = cur;
            }
            errorWriter.add("xpath", buf.toString());
        }

        public void close() {
        }

        public String peekNextChild() {
            return current().peekNextChild();
        }

        public String getNodeName() {
            return unescapeXmlName(current().node.tagName);
        }

        public String getValue() {
            return Util.fixNull(current().node.value);
        }

        public String getAttribute(String name) {
            return current().node.getAttribute(name);
        }

        public String getAttribute(int index) {
            return current().node.getAttribute(index);
        }

        public int getAttributeCount() {
            return current().node.getAttributeCount();
        }

        public String getAttributeName(int index) {
            return unescapeXmlName(current().node.getAttributeName(index));
        }
    }

    public static class WriterImpl extends AbstractXmlWriter {
        private static class Pending {
            final String tagName;
            List<XStreamDOM> children;
            List<String> attributes = new ArrayList<String>();
            String value;

            private Pending(String tagName) {
                this.tagName = tagName;
            }

            void addChild(XStreamDOM dom) {
                if (children==null)
                    children = new ArrayList<XStreamDOM>();
                children.add(dom);
            }

            XStreamDOM toDOM() {
                return new XStreamDOM(tagName,attributes.toArray(new String[attributes.size()]),children,value);
            }
        }

        private final Stack<Pending> pendings = new Stack<Pending>();

        public WriterImpl() {
            pendings.push(new Pending(null));   // to get the final result
        }

        public void startNode(String name) {
            pendings.push(new Pending(escapeXmlName(name)));
        }



        public void endNode() {
            XStreamDOM dom = pendings.pop().toDOM();
            pendings.peek().addChild(dom);
        }

        public void addAttribute(String name, String value) {
            List<String> atts = pendings.peek().attributes;
            atts.add(escapeXmlName(name));
            atts.add(value);
        }

        public void setValue(String text) {
            pendings.peek().value = text;
        }

        public void flush() {
        }

        public void close() {
        }

        public HierarchicalStreamWriter underlyingWriter() {
            return this;
        }

        public XStreamDOM getOutput() {
            if (pendings.size()!=1)     throw new IllegalStateException();
            return pendings.peek().children.get(0);
        }
    }

    public static class ConverterImpl implements Converter {
        public boolean canConvert(Class type) {
            return type==XStreamDOM.class;
        }

        /**
         * {@link XStreamDOM} holds infoset (which is 'escaped' from XStream's PoV),
         * whereas {@link HierarchicalStreamWriter} expects unescaped names,
         * so we need to unescape it first before calling into {@link HierarchicalStreamWriter}.
         */
        // TODO: ideally we'd like to use the contextual HierarchicalStreamWriter to unescape,
        // but this object isn't exposed to us
        private String unescape(String s) {
            return REPLACER.unescapeName(s);
        }

        private String escape(String s) {
            return REPLACER.escapeName(s);
        }

        public void marshal(Object source, HierarchicalStreamWriter w, MarshallingContext context) {
            XStreamDOM dom = (XStreamDOM)source;
            w.startNode(unescape(dom.tagName));
            for (int i=0; i<dom.attributes.length; i+=2)
                w.addAttribute(unescape(dom.attributes[i]),dom.attributes[i+1]);
            if (dom.value!=null)
                w.setValue(dom.value);
            else {
                for (XStreamDOM c : Util.fixNull(dom.children)) {
                    marshal(c, w, context);
                }
            }
            w.endNode();
        }

        /**
         * Unmarshals a single child element.
         */
        public XStreamDOM unmarshal(HierarchicalStreamReader r, UnmarshallingContext context) {
            r.moveDown();
            XStreamDOM dom = unmarshalElement(r,context);
            r.moveUp();
            return dom;
        }

        public XStreamDOM unmarshalElement(HierarchicalStreamReader r, UnmarshallingContext context) {
            String name = escape(r.getNodeName());

            int c = r.getAttributeCount();
            String[] attributes = new String[c*2];
            for (int i=0; i<c; i++) {
                attributes[i*2]   = escape(r.getAttributeName(i));
                attributes[i*2+1] = r.getAttribute(i);
            }

            List<XStreamDOM> children = null;
            String value = null;
            if (r.hasMoreChildren()) {
                children = new ArrayList<XStreamDOM>();
                while (r.hasMoreChildren()) {
                    children.add(unmarshal(r, context));
                }
            } else {
                value = r.getValue();
            }

            return new XStreamDOM(name,attributes,children,value);
        }
    }

    public static XmlFriendlyReplacer REPLACER = new XmlFriendlyReplacer();
}
1119788
public function inflectPackageVars($vars)
    {
        if ($this->matchesCakeVersion('>=', '3.0.0')) {
            return $vars;
        }

        $nameParts = explode('/', $vars['name']);
        foreach ($nameParts as &$value) {
            $value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value));
            $value = str_replace(array('-', '_'), ' ', $value);
            $value = str_replace(' ', '', ucwords($value));
        }
        $vars['name'] = implode('/', $nameParts);

        return $vars;
    }
233652
public static Map<String, String> getVariableMapByPrefix(
      final Collection<Variable> variables, final String prefix) {
    final Map<String, String> shortlistMap = new HashMap<>();
    if (variables != null && prefix != null) {
      for (final Variable var : getVariablesByRegex(variables,
          Reportal.REPORTAL_CONFIG_PREFIX_REGEX)) {
        shortlistMap
            .put(var.getTitle().replaceFirst(prefix, ""), var.getName());
      }
    }
    return shortlistMap;
  }
345081
public String getKey(Map<String, String> variableValues)
    {
        StringBuilder key = new StringBuilder();
        for ( ConfigurationKeyPart p : parts )
        {
            if ( p.isVariable() )
            {
                String value = variableValues.get(p.getValue());
                if ( value == null )
                {
                    log.warn("No value found for variable: " + p.getValue());
                    value = "";
                }
                key.append(value);
            }
            else
            {
                key.append(p.getValue());
            }
        }

        return key.toString();
    }
411537
protected function expandTemplate($template, array $variables = null)
    {
        $expansionVars = $this->getConfig()->toArray();
        if ($variables) {
            $expansionVars = $variables + $expansionVars;
        }

        return $this->getUriTemplate()->expand($template, $expansionVars);
    }