Mise à jour de 'src/fr/sae/JSonInspector/Main.java'

This commit is contained in:
Romain BESSON 2023-01-16 22:30:31 +01:00
parent 44dde661eb
commit 56249a06a3

View File

@ -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;
}
}