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

net.sf.jcmdlineparser.strategy.escape.StringHanderNormal Maven / Gradle / Ivy

Go to download

A highly adaptive and easy to use command line option parser for Java applications.

The newest version!
/**********************************************************************
Copyright (c) 2009-2010 Alexander Kerner. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 ***********************************************************************/

package net.sf.jcmdlineparser.strategy.escape;

import net.sf.jcmdlineparser.strategy.StrategyRules;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class StringHanderNormal implements StringHandler {
	
	private final Logger log = LoggerFactory.getLogger(StringHanderNormal.class);
	
	StrategyRules rules;

	public StringHanderNormal(StrategyRules rules) {
		this.rules = rules;
	}

	public String handleString(String string) {
		final StringBuilder sb = new StringBuilder();
		for(int i = 0; i < string.length(); i++){
			final char c = string.charAt(i);
//			log.debug("["+c+"]");
			if(rules.isEscapeChar(c)){
				log.debug("escaping with substring: "+string.substring(i+1));
				return sb.toString() + new StringHandlerEscape(rules).handleString(string.substring(i+1));
			}
			else if (rules.isEscapeFlag(c)){
				return sb.toString() + new StringHandlerEscapeFlag(rules).handleString(string.substring(i+1));
			}
			else
				sb.append(c);
		}
		return sb.toString();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy