2
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3
* Copyright (C) 2009 - DIGITEO - Clément DAVID
5
* This file must be used under the terms of the CeCILL.
6
* This source file is licensed as described in the file COPYING, which
7
* you should have received as part of this distribution. The terms
8
* are also available at
9
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13
package org.scilab.modules.xcos.utils;
15
import java.util.HashMap;
17
import java.util.regex.Matcher;
18
import java.util.regex.Pattern;
21
* Perform useful conversions between a style string and key/value based map.
23
public final class StyleMap extends HashMap<String, String> {
25
private static final Pattern P = Pattern.compile("(\\w+)(=(\\w+))?;?");
26
private static final int KEY_GROUP = 1;
27
private static final int VALUE_GROUP = 3;
30
* Create a hashmap from a style string
31
* @param style The string which contains key=value list
33
public StyleMap(String style) {
35
Matcher m = P.matcher(style);
38
String key = m.group(KEY_GROUP);
39
String value = m.group(VALUE_GROUP);
45
* Export to a key=value; string
46
* @return formatted string
49
public String toString() {
50
StringBuilder str = new StringBuilder();
51
String valueRef = null;
53
for (Map.Entry<String, String> entry : entrySet()) {
54
str.append(entry.getKey());
56
valueRef = entry.getValue();
57
if (valueRef != null) {
64
return str.toString();