|
@ -142,42 +142,84 @@ bool Jupiter::File::load(const Jupiter::ReadableString &file) |
|
|
bool Jupiter::File::load(FILE *file) |
|
|
bool Jupiter::File::load(FILE *file) |
|
|
{ |
|
|
{ |
|
|
Jupiter::String buffer(defaultBufferSize); |
|
|
Jupiter::String buffer(defaultBufferSize); |
|
|
int c = fgetc(file); |
|
|
|
|
|
|
|
|
|
|
|
if (c == EOF) |
|
|
int chr; |
|
|
return false; |
|
|
|
|
|
if (containsSymbol(ENDL, static_cast<char>(c))) |
|
|
while (true) |
|
|
|
|
|
{ |
|
|
|
|
|
chr = fgetc(file); |
|
|
|
|
|
|
|
|
|
|
|
if (chr == EOF) |
|
|
|
|
|
{ |
|
|
|
|
|
if (buffer.isNotEmpty()) |
|
|
{ |
|
|
{ |
|
|
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer)); |
|
|
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer)); |
|
|
c = fgetc(file); |
|
|
|
|
|
if (c == EOF) |
|
|
|
|
|
return true; |
|
|
return true; |
|
|
if (containsSymbol(ENDL, static_cast<char>(c)) == false) |
|
|
|
|
|
buffer.concat(static_cast<char>(c)); |
|
|
|
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
buffer.concat(static_cast<char>(c)); |
|
|
|
|
|
|
|
|
|
|
|
for (;;) |
|
|
return Jupiter::File::data_->lines.size() != 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (static_cast<char>(chr) == '\r') // new line
|
|
|
|
|
|
{ |
|
|
|
|
|
new_line_r: |
|
|
|
|
|
|
|
|
|
|
|
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer)); |
|
|
|
|
|
buffer.erase(); |
|
|
|
|
|
|
|
|
|
|
|
// check for optional trailing \n
|
|
|
|
|
|
|
|
|
|
|
|
chr = fgetc(file); |
|
|
|
|
|
|
|
|
|
|
|
switch (chr) |
|
|
{ |
|
|
{ |
|
|
c = fgetc(file); |
|
|
case EOF: |
|
|
if (c == EOF) |
|
|
|
|
|
return true; |
|
|
return true; |
|
|
if (containsSymbol(ENDL, static_cast<char>(c))) |
|
|
|
|
|
|
|
|
case '\r': |
|
|
|
|
|
goto new_line_r; |
|
|
|
|
|
|
|
|
|
|
|
case '\n': |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
buffer += static_cast<char>(chr); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (static_cast<char>(chr) == '\n') // new line
|
|
|
{ |
|
|
{ |
|
|
|
|
|
new_line_n: |
|
|
|
|
|
|
|
|
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer)); |
|
|
Jupiter::File::data_->lines.add(new Jupiter::StringS(buffer)); |
|
|
buffer.truncate(buffer.size()); |
|
|
buffer.erase(); |
|
|
c = fgetc(file); |
|
|
|
|
|
if (c == EOF) |
|
|
// check for optional trailing \r
|
|
|
|
|
|
|
|
|
|
|
|
chr = fgetc(file); |
|
|
|
|
|
|
|
|
|
|
|
switch (chr) |
|
|
|
|
|
{ |
|
|
|
|
|
case EOF: |
|
|
return true; |
|
|
return true; |
|
|
if (containsSymbol(ENDL, static_cast<char>(c)) == false) |
|
|
|
|
|
buffer.concat(static_cast<char>(c)); |
|
|
case '\n': |
|
|
|
|
|
goto new_line_n; |
|
|
|
|
|
|
|
|
|
|
|
case '\r': |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
buffer += static_cast<char>(chr); |
|
|
} |
|
|
} |
|
|
else |
|
|
|
|
|
buffer.concat(static_cast<char>(c)); |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return true; |
|
|
buffer += static_cast<char>(chr); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Jupiter::File::unload() |
|
|
void Jupiter::File::unload() |
|
|