Parser & Fix puzzle's origin from db

This commit is contained in:
jeffcheasey88 2023-03-14 11:07:49 +01:00
parent 69acf0966e
commit d3c9ad22e5
5 changed files with 48 additions and 8 deletions

View file

@ -30,6 +30,7 @@ public class Variable {
matcher.matches();
boolean hasEquals = false;
boolean fromMinus = false;
String body = matcher.group(2);
while(true){
int space = indexOf(body, "\\s+");
@ -52,7 +53,11 @@ public class Variable {
this.value = new Value(value);
body = body.substring(value.length()+1);
break;
}else if(fromMinus){
System.out.println("fromMinus "+value);
this.name = value;
body = body.substring(value.length()+1);
break;
} else if(min == space){
if(value.isEmpty()){
do {
@ -75,10 +80,31 @@ public class Variable {
hasEquals = true;
body = body.substring(value.length()+1);
}else if(min == minus){
value = value+"<";
System.out.println("MINUS");
int maxus = 1;
while(maxus > 0){
char current = body.charAt(value.length());
value+=current;
if(current == '<'){
maxus++;
}
if(current == '>'){
maxus--;
}
}
this.type = value;
body = body.substring(value.length());
while(indexOf(body, "\\s+") == 0){
body = body.substring(1);
}
fromMinus = true;
System.out.println("fromMinus on "+body);
}else if(min == quote){
this.name = value;
body = body.substring(value.length());
break;
}else {
break;
}
}

View file

@ -67,14 +67,29 @@ class VariableTest {
void case4(){
try {
Variable variable = new Variable();
variable.parse("Test<Test>t; ");
variable.parse("Testas<Test>t; ");
assertEquals(0, variable.getModifier());
assertEquals("Test<Test>", variable.getType());
assertEquals("Testas<Test>", variable.getType());
assertEquals("t", variable.getName());
assertNull(variable.getValue());
}catch(Exception e){
fail(e);
}
}
@Test
void case5(){
try {
Variable variable = new Variable();
variable.parse(" int i,j,k,l=1; ");
assertEquals(0, variable.getModifier());
assertEquals("int", variable.getType());
assertEquals("i", variable.getName());
assertNull(variable.getValue());
}catch(Exception e){
fail(e);
}
}
}

View file

@ -68,7 +68,7 @@ public class DatabaseRepository {
private Puzzle makePuzzle(ResultSet puzzleResult) throws SQLException {
return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"),
puzzleResult.getString("content"), null, "", 0, puzzleResult.getInt("origin"));
puzzleResult.getString("content"), null, "", 0, hasColumn(puzzleResult, "origin") ? puzzleResult.getInt("origin") : -1);
}
private Chapter makeChapter(ResultSet chapterResult) throws SQLException {

View file

@ -1 +0,0 @@
ceci est du code source java