Merge pull request #13 from axell-brendow/bugfix/fix-myio-eof-detection

Bugfix/fix MyIO.readLine() and MyIO.readString() EOF detection
This commit is contained in:
Felipe Domingos 2020-11-13 14:26:19 -03:00 committed by GitHub
commit fefe3aa64e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 16 deletions

View File

@ -150,16 +150,14 @@ class MyIO {
public static String readString(){ public static String readString(){
String s = ""; String s = "";
char tmp;
try{ try{
do{ char tmp = (char) in.read();
tmp = (char)in.read(); while (tmp != '\n' && tmp != ' ' && tmp != '\t' && tmp != (char) -1) {
if(tmp != '\n' && tmp != ' ' && tmp != 13){ if (tmp != '\r') s += tmp;
s += tmp; tmp = (char) in.read();
} }
}while(tmp != '\n' && tmp != ' ');
}catch(IOException ioe){ }catch(IOException ioe){
System.out.println("lerPalavra: " + ioe.getMessage()); System.out.println("MyIO.readString: " + ioe.getMessage());
} }
return s; return s;
} }
@ -174,16 +172,14 @@ class MyIO {
public static String readLine(){ public static String readLine(){
String s = ""; String s = "";
char tmp;
try{ try{
do{ char tmp = (char) in.read();
tmp = (char)in.read(); while (tmp != '\n' && tmp != (char) -1) {
if(tmp != '\n' && tmp != 13){ if (tmp != '\r') s += tmp;
s += tmp; tmp = (char) in.read();
} }
}while(tmp != '\n');
}catch(IOException ioe){ }catch(IOException ioe){
System.out.println("lerPalavra: " + ioe.getMessage()); System.out.println("MyIO.readLine: " + ioe.getMessage());
} }
return s; return s;
} }