Mise à jour de 'src/fr/sae/JSonInspector/Main.java'
This commit is contained in:
parent
44dde661eb
commit
56249a06a3
@ -37,6 +37,9 @@ public class Main {
|
||||
BufferedReader buff = new BufferedReader(new InputStreamReader(f.openStream()));
|
||||
String line;
|
||||
while ((line = buff.readLine()) != null) {
|
||||
line = line.replaceAll("\t", "");
|
||||
line = line.replaceAll("\n", "");
|
||||
line = line.replaceAll(" ", "");
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
@ -47,42 +50,4 @@ public class Main {
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String cleanFile(String file) {
|
||||
char[] chars = file.toCharArray();
|
||||
boolean inString = false, inValue = false;
|
||||
String cleanedFile = "";
|
||||
|
||||
for (char currentChar : chars) {
|
||||
if (!inString && !inValue) {
|
||||
if (currentChar == '"') {
|
||||
inString = true;
|
||||
cleanedFile += currentChar;
|
||||
} else if (isJsonSyntax(currentChar)) {
|
||||
cleanedFile += currentChar;
|
||||
}
|
||||
} else if (currentChar == '"') {
|
||||
inString = false;
|
||||
cleanedFile += currentChar;
|
||||
} else if (currentChar == ':') {
|
||||
inValue = true;
|
||||
cleanedFile += currentChar;
|
||||
} else {
|
||||
cleanedFile += currentChar;
|
||||
}
|
||||
}
|
||||
|
||||
return cleanedFile;
|
||||
}
|
||||
|
||||
private static boolean isJsonSyntax(char character) {
|
||||
boolean openingArray = character == '[', closingArray = character == ']';
|
||||
boolean openingObject = character == '{', closingObject = character == '}';
|
||||
boolean virgule = character == ',', deuxPoints = character == ':';
|
||||
|
||||
if (openingArray || closingArray || openingObject || closingObject || virgule || deuxPoints) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user