eclipse plugin: Trim the quotes when adding a new primitive

This commit is contained in:
Timotei Dolean 2011-07-26 15:36:15 +00:00
parent 5bdcb47e8f
commit 7c04c02423
2 changed files with 28 additions and 4 deletions

View file

@ -192,7 +192,9 @@ public class SchemaParser
"Error. invalid primitive on line :" + index); //$NON-NLS-1$
continue;
}
primitives_.put(tokens[0].trim(), tokens[1].trim());
primitives_.put(tokens[0].trim(),
StringUtils.trimQuotes( tokens[1].trim( ) ) );
}
else if (tagStack.peek().equals("description")) //$NON-NLS-1$
{

View file

@ -144,9 +144,9 @@ public class StringUtils
* @param string The string to trim
* @return A new string that doesn't have any trailling separators
*/
public static String trimPathSeparators(String string)
public static String trimEndPathSeparators(String string)
{
if (string == null || string.isEmpty())
if ( isNullOrEmpty( string ) )
return ""; //$NON-NLS-1$
while (string.charAt(string.length() - 1) == '/' ||
@ -155,6 +155,28 @@ public class StringUtils
return string;
}
/**
* Trims any quotes " of the specified string
* @param string The string to trim
* @return A new string with the quotes trimmed
*/
public static String trimQuotes( String string )
{
if ( isNullOrEmpty( string ) )
return "";
while ( string.charAt( 0 ) == '"' )
string = string.substring( 1 );
int strSize = string.length( ) - 1;
while ( strSize >= 0 && string.charAt( strSize ) == '"' ){
string = string.substring( 0, strSize );
-- strSize;
}
return string;
}
/**
* Normalizez the path given by the string, removing repeated separators
* and replacing them by '|'
@ -167,7 +189,7 @@ public class StringUtils
if (path == null)
return ""; //$NON-NLS-1$
String str = StringUtils.trimPathSeparators(path);
String str = StringUtils.trimEndPathSeparators(path);
StringBuilder sb = new StringBuilder(str.length());
// normalize strings - remove repeating separators and replace them by |