Parser & Fix puzzle's origin from db
This commit is contained in:
parent
69acf0966e
commit
d3c9ad22e5
5 changed files with 48 additions and 8 deletions
|
@ -30,6 +30,7 @@ public class Variable {
|
||||||
matcher.matches();
|
matcher.matches();
|
||||||
|
|
||||||
boolean hasEquals = false;
|
boolean hasEquals = false;
|
||||||
|
boolean fromMinus = false;
|
||||||
String body = matcher.group(2);
|
String body = matcher.group(2);
|
||||||
while(true){
|
while(true){
|
||||||
int space = indexOf(body, "\\s+");
|
int space = indexOf(body, "\\s+");
|
||||||
|
@ -52,7 +53,11 @@ public class Variable {
|
||||||
this.value = new Value(value);
|
this.value = new Value(value);
|
||||||
body = body.substring(value.length()+1);
|
body = body.substring(value.length()+1);
|
||||||
break;
|
break;
|
||||||
|
}else if(fromMinus){
|
||||||
|
System.out.println("fromMinus "+value);
|
||||||
|
this.name = value;
|
||||||
|
body = body.substring(value.length()+1);
|
||||||
|
break;
|
||||||
} else if(min == space){
|
} else if(min == space){
|
||||||
if(value.isEmpty()){
|
if(value.isEmpty()){
|
||||||
do {
|
do {
|
||||||
|
@ -75,10 +80,31 @@ public class Variable {
|
||||||
hasEquals = true;
|
hasEquals = true;
|
||||||
body = body.substring(value.length()+1);
|
body = body.substring(value.length()+1);
|
||||||
}else if(min == minus){
|
}else if(min == minus){
|
||||||
|
value = value+"<";
|
||||||
System.out.println("MINUS");
|
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;
|
break;
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,14 +67,29 @@ class VariableTest {
|
||||||
void case4(){
|
void case4(){
|
||||||
try {
|
try {
|
||||||
Variable variable = new Variable();
|
Variable variable = new Variable();
|
||||||
variable.parse("Test<Test>t; ");
|
variable.parse("Testas<Test>t; ");
|
||||||
|
|
||||||
assertEquals(0, variable.getModifier());
|
assertEquals(0, variable.getModifier());
|
||||||
assertEquals("Test<Test>", variable.getType());
|
assertEquals("Testas<Test>", variable.getType());
|
||||||
assertEquals("t", variable.getName());
|
assertEquals("t", variable.getName());
|
||||||
assertNull(variable.getValue());
|
assertNull(variable.getValue());
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
fail(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class DatabaseRepository {
|
||||||
|
|
||||||
private Puzzle makePuzzle(ResultSet puzzleResult) throws SQLException {
|
private Puzzle makePuzzle(ResultSet puzzleResult) throws SQLException {
|
||||||
return new Puzzle(puzzleResult.getInt("id_puzzle"), puzzleResult.getString("name"),
|
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 {
|
private Chapter makeChapter(ResultSet chapterResult) throws SQLException {
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
ceci est du code source java
|
|
Loading…
Add table
Reference in a new issue