Java String Extract extractParamsFromUriTemplateFragment(String value)

Here you can find the source of extractParamsFromUriTemplateFragment(String value)

Description

Extracts all the character sequences inside of curly braces ('{' and '}') and returns them as a list of strings

License

Open Source License

Parameter

Parameter Description
value the given value

Return

the list of character sequences, or an empty list

Declaration

public static List<String> extractParamsFromUriTemplateFragment(String value) 

Method Source Code

//package com.java2s;
/******************************************************************************* 
 * Copyright (c) 2008 - 2014 Red Hat, Inc. and others. 
 * Distributed under license by Red Hat, Inc. All rights reserved. 
 * This program is made available under the terms of the 
 * Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html 
 * //from  www . ja va 2  s .  c  om
 * Contributors: 
 * Xavier Coulon - Initial API and implementation 
 ******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Extracts all the character sequences inside of curly braces ('{' and '}')
     * and returns them as a list of strings
     * 
     * @param value
     *            the given value
     * @return the list of character sequences, or an empty list
     */
    public static List<String> extractParamsFromUriTemplateFragment(String value) {
        List<String> params = new ArrayList<String>();
        int beginIndex = -1;
        while ((beginIndex = value.indexOf("{", beginIndex + 1)) != -1) {
            int semicolonIndex = value.indexOf(":", beginIndex);
            int closingCurlyBraketIndex = value.indexOf("}", beginIndex);
            int endIndex = (semicolonIndex != -1) ? Math.min(semicolonIndex, closingCurlyBraketIndex)
                    : closingCurlyBraketIndex;
            if (endIndex == -1) {
                // missing end bracket
                break;
            }
            params.add(value.substring(beginIndex + 1, endIndex).trim());
        }
        return params;
    }
}

Related

  1. extractNoPublicDomains(String domains)
  2. extractNumberFromInput(String command)
  3. extractNumbers(String text)
  4. extractPacket(String serverPacket)
  5. extractParameters(String uri)
  6. extractReferences(String value)
  7. extractStreetName(String address)
  8. extractStrings(String s)
  9. extractStringsAroundDots(String s)