Skip to content

Commit

Permalink
error message when column name is 01,02or so on in computed
Browse files Browse the repository at this point in the history
columns(T55384)
  • Loading branch information
mianrui authored and mwu committed Dec 21, 2012
1 parent a9aa34b commit c930037
Showing 1 changed file with 70 additions and 3 deletions.
Expand Up @@ -1715,13 +1715,80 @@ && isBlankProperty( txtParams[0].getText( ) ) )
}
return getOKStatus( );
}


/**
* If text is a decimal presentation of int32 value, then text is index.
* In this case return true and make send out error message. Otherwise
* return false means the column name is right.
*/
private boolean isNumeric( String text )
{
Pattern pattern = Pattern.compile("-[0-9]*|[0-9]*");
return pattern.matcher(text).matches();
long indexTest = indexFromString( text );
if ( indexTest >= 0 )
{
return true;
}
return false;
}

private long indexFromString( String str )
{
// The length of the decimal string representation of
// Integer.MAX_VALUE, 2147483647
final int MAX_VALUE_LENGTH = 10;

int len = str.length( );
if ( len > 0 )
{
int i = 0;
boolean negate = false;
int c = str.charAt( 0 );
if ( c == '-' )
{
if ( len > 1 )
{
c = str.charAt( 1 );
i = 1;
negate = true;
}
}
c -= '0';
if ( 0 <= c
&& c <= 9
&& len <= ( negate ? MAX_VALUE_LENGTH + 1
: MAX_VALUE_LENGTH ) )
{
// Use negative numbers to accumulate index to handle
// Integer.MIN_VALUE that is greater by 1 in absolute value
// then Integer.MAX_VALUE
int index = -c;
int oldIndex = 0;
i++;
if ( index != 0 )
{
// Note that 00, 01, 000 etc. are not indexes
while ( i != len
&& 0 <= ( c = str.charAt( i ) - '0' ) && c <= 9 )
{
oldIndex = index;
index = 10 * index - c;
i++;
}
}
// Make sure all characters were consumed and that it
// couldn't
// have overflowed.
if ( i == len
&& ( oldIndex > ( Integer.MIN_VALUE / 10 ) || ( oldIndex == ( Integer.MIN_VALUE / 10 ) && c <= ( negate
? -( Integer.MIN_VALUE % 10 )
: ( Integer.MAX_VALUE % 10 ) ) ) ) )
{
return 0xFFFFFFFFL & ( negate ? index : -index );
}
}
}
return -1L;
}
private boolean checkExpressionBindingFields( ) throws BirtException
{
for ( int i = 0; i < txtParams.length; i++ )
Expand Down

0 comments on commit c930037

Please sign in to comment.