Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
src/bsh/bsh.jj
src/bsh/Parser.java
# src/bsh/Parser.java
src/bsh/ParserConstants.java
src/bsh/ParserTokenManager.java
src/bsh/ParserTreeConstants.java
classes/*
bin/*

# compiled source #
###################
Expand Down
29 changes: 29 additions & 0 deletions src/bsh/BSHLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,36 @@ private char getEscapeChar(char ch)
return ch;
}

public static String decode(String str) {
StringBuilder sb = new StringBuilder(str.length());
char[] chars = str.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (i + 1 < chars.length && c == '\\' && chars[i + 1] == 'u') {
char cc = 0;
for (int j = 0; j < 4; j++) {
char ch = Character.toLowerCase(chars[i + 2 + j]);
if ('0' <= ch && ch <= '9' || 'a' <= ch && ch <= 'f' || 'A' <= ch && ch <= 'F') {
cc |= (Character.digit(ch, 16) << (3 - j) * 4);
} else {
cc = 0;
break;
}
}
if (cc > 0) {
i += 5;
sb.append(cc);
continue;
}
}
sb.append(c);
}
return sb.toString();
}

public void charSetup(String str)
{
str = decode(str);
char ch = str.charAt(0);
if(ch == '\\')
{
Expand All @@ -104,6 +132,7 @@ public void charSetup(String str)

void stringSetup(String str)
{
str = decode(str);
StringBuilder buffer = new StringBuilder();
int len = str.length();
for(int i = 0; i < len; i++)
Expand Down
79 changes: 5 additions & 74 deletions src/bsh/JavaCharStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static final int hexval(char c) throws java.io.IOException {
protected boolean prevCharIsLF = false;

protected java.io.Reader inputStream;
protected static final java.io.IOException fillException = new java.io.IOException("FillBuff");

protected char[] nextCharBuf;
protected char[] buffer;
Expand Down Expand Up @@ -136,7 +137,7 @@ protected void FillBuff() throws java.io.IOException
4096 - maxNextCharInd)) == -1)
{
inputStream.close();
throw new java.io.IOException();
throw fillException;
}
else
maxNextCharInd += i;
Expand Down Expand Up @@ -261,79 +262,9 @@ public char readChar() throws java.io.IOException
if (++bufpos == available)
AdjustBuffSize();

if ((buffer[bufpos] = c = ReadByte()) == '\\')
{
UpdateLineColumn(c);

int backSlashCnt = 1;

for (;;) // Read all the backslashes
{
if (++bufpos == available)
AdjustBuffSize();

try
{
if ((buffer[bufpos] = c = ReadByte()) != '\\')
{
UpdateLineColumn(c);
// found a non-backslash char.
if ((c == 'u') && ((backSlashCnt & 1) == 1))
{
if (--bufpos < 0)
bufpos = bufsize - 1;

break;
}

backup(backSlashCnt);
return '\\';
}
}
catch(java.io.IOException e)
{
if (backSlashCnt > 1)
backup(backSlashCnt);

return '\\';
}

UpdateLineColumn(c);
backSlashCnt++;
}

// Here, we have seen an odd number of backslash's followed by a 'u'
try
{
while ((c = ReadByte()) == 'u')
++column;

buffer[bufpos] = c = (char)(hexval(c) << 12 |
hexval(ReadByte()) << 8 |
hexval(ReadByte()) << 4 |
hexval(ReadByte()));

column += 4;
}
catch(java.io.IOException e)
{
throw new Error("Invalid escape character at line " + line +
" column " + column + ".");
}

if (backSlashCnt == 1)
return c;
else
{
backup(backSlashCnt - 1);
return '\\';
}
}
else
{
UpdateLineColumn(c);
return (c);
}
buffer[bufpos] = c = ReadByte();
UpdateLineColumn(c);
return (c);
}

/**
Expand Down
21 changes: 12 additions & 9 deletions src/bsh/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ vs. imported class names (at least in the simple case - see
Class clas = null;
int i = 1;
String className = null;
for(; i <= countParts(evalName); i++)
{
final int parts = countParts(evalName);
for(; i <= parts; i++) {
className = prefix(evalName, i);
if ( (clas = namespace.getClass(className)) != null )
break;
Expand All @@ -305,7 +305,7 @@ vs. imported class names (at least in the simple case - see
if ( clas != null ) {
return completeRound(
className,
suffix( evalName, countParts(evalName)-i ),
suffix( evalName, parts-i ),
new ClassIdentifier(clas)
);
}
Expand Down Expand Up @@ -374,7 +374,7 @@ vs. imported class names (at least in the simple case - see
if ( evalBaseObject instanceof ClassIdentifier )
{
Class clas = ((ClassIdentifier)evalBaseObject).getTargetClass();
String field = prefix(evalName, 1);
String field = varName;

// Class qualified 'this' reference from inner class.
// e.g. 'MyOuterClass.this'
Expand Down Expand Up @@ -410,8 +410,12 @@ vs. imported class names (at least in the simple case - see

// inner class?
if ( obj == null ) {
String iclass = clas.getName()+"$"+field;
Class c = namespace.getClass( iclass );
Class c = Reflect.findInnerClass(clas, field);
if (c == null) {
String iclass = clas.getName() + "$" + field;
c = namespace.getClass(iclass);
}

if ( c != null )
obj = new ClassIdentifier(c);
}
Expand All @@ -436,7 +440,7 @@ a class type.
Some kind of field access?
*/

String field = prefix(evalName, 1);
String field = varName;

// length access on array?
if ( field.equals("length") && evalBaseObject.getClass().isArray() )
Expand Down Expand Up @@ -999,8 +1003,7 @@ private String getHelp( Class commandClass )

public static boolean isCompound(String value)
{
return value.indexOf('.') != -1 ;
//return countParts(value) > 1;
return value.indexOf('.') != -1;
}

static int countParts(String value)
Expand Down
Loading