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

com.day.util.NameValuePair Maven / Gradle / Ivy

/*
 * $Id: NameValuePair.java 12345 2004-08-22 04:56:09Z fielding $
 *
 * Copyright 1997-2004 Day Management AG
 * Barfuesserplatz 6, 4001 Basel, Switzerland
 * All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Day Management AG, ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Day.
 */
package com.day.util;

/**
 * The NameValuePair class implements a structure of a name and an optional
 * value.
 *
 * @version $Revision: 1.4 $, $Date: 2004-08-22 06:56:09 +0200 (Sun, 22 Aug 2004) $
 * @author tripod
 * @since coati
 * @audience wad
 */
public class NameValuePair {

    /** the name */
    private final String name;

    /** the value */
    private final String value;

    /**
     * Creates a new name value pair
     */
    public NameValuePair(String name, String value) {
	this.name = name;
	this.value = value;
    }

    /**
     * Gets the name
     */
    public String getName() {
	return name;
    }

    /**
     * Gets the value
     */
    public String getValue() {
	return value;
    }

    /**
     * Parses a line of the form:
     * {ws} name {ws} ["=" {ws} value {ws}];
     *
     * @param str the string to parse
     */
    public static NameValuePair parse(String str) {
	return parse(str, '=');
    }

    /**
     * Parses a line of the form:
     * {ws} name {ws} ["<equal>" {ws} value {ws}];
     *
     * @param str the string to parse
     * @param equal the delimiter for the equal sign
     */
    public static NameValuePair parse(String str, char equal) {

	int state=0;
	int lastState=0;
	int nameStart=0;
	int nameEnd=0;
	StringBuffer value = new StringBuffer();
	for (int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy