net.segoia.util.data.GenericNameValueContextUtil Maven / Gradle / Ivy
The newest version!
/**
* commons - Various Java Utils
* Copyright (C) 2009 Adrian Cristian Ionescu - https://github.com/acionescu
*
* 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.segoia.util.data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import net.segoia.commons.exceptions.ContextAwareException;
import net.segoia.commons.exceptions.ExceptionContext;
import net.segoia.util.parser.Parser;
import net.segoia.util.parser.ParserHandlerFactory;
import net.segoia.util.parser.Symbol;
import net.segoia.util.parser.SymbolFlag;
import net.segoia.util.parser.SymbolType;
import net.segoia.util.parser.event.AssociationEvent;
import net.segoia.util.parser.event.GroupEvent;
import net.segoia.util.parser.event.ParseEventHandler;
public class GenericNameValueContextUtil {
private static Parser parser;
static {
ContextParserHandler handler = new ContextParserHandler();
parser = new Parser();
parser.setHandlerFactory(new ParserHandlerFactory(handler));
Symbol commaSymbol = new Symbol(",", SymbolType.SEPARATE);
Symbol listSymbol = new Symbol("[", SymbolType.GROUP_START);
listSymbol.addNestedSymbol(new Symbol("]", SymbolType.GROUP_END));
listSymbol.addNestedSymbol(listSymbol);
listSymbol.addNestedSymbol(commaSymbol);
listSymbol.addFlag(SymbolFlag.IGNORE_EMPTY);
Symbol mapSymbol = new Symbol("{", SymbolType.GROUP_START);
mapSymbol.addNestedSymbol(new Symbol("}", SymbolType.GROUP_END));
mapSymbol.addNestedSymbol(commaSymbol);
mapSymbol.addNestedSymbol(new Symbol("=", SymbolType.ASSOCIATE));
mapSymbol.addNestedSymbol(mapSymbol);
mapSymbol.addFlag(SymbolFlag.IGNORE_EMPTY);
mapSymbol.addNestedSymbol(listSymbol);
listSymbol.addNestedSymbol(mapSymbol);
parser.addSymbol(listSymbol);
parser.addSymbol(mapSymbol);
parser.setUseEscapeCharacterOn(true);
}
public static GenericNameValueContext parse(String input) {
try {
Deque
© 2015 - 2025 Weber Informatics LLC | Privacy Policy