mirror of
https://github.com/2martens/uni.git
synced 2026-05-06 19:36:26 +02:00
[ES] Added missing functionality
Signed-óff-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -352,20 +352,10 @@ const char* readString(File file)
|
|||||||
if (file) {
|
if (file) {
|
||||||
unsigned long fileSize = file.size();
|
unsigned long fileSize = file.size();
|
||||||
char result[fileSize];
|
char result[fileSize];
|
||||||
int i = 0;
|
int readBytes = file.readBytesUntil('\n', result, fileSize);
|
||||||
while (file.available()) {
|
result[readBytes] = '\0';
|
||||||
char c = file.read();
|
|
||||||
if (c != '\n') {
|
|
||||||
result[i] = c;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
result[i] = '\0';
|
|
||||||
break; // allows for multiple calls of the method for iterative reading
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
readStringLength = i;
|
readStringLength = readBytes + 1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -380,12 +370,30 @@ const char* readString(File file)
|
|||||||
*
|
*
|
||||||
* @param const int* input
|
* @param const int* input
|
||||||
* @param int length
|
* @param int length
|
||||||
|
* @param char delimeter
|
||||||
*/
|
*/
|
||||||
const int* explodeString(const char* input, int length)
|
const int* explodeString(const char* input, int length, char delimeter)
|
||||||
{
|
{
|
||||||
int result[length] = {};
|
int result[length] = {};
|
||||||
|
char tmp[length] = {};
|
||||||
|
int nthChar = 0;
|
||||||
|
int nthInt = 0;
|
||||||
|
|
||||||
// TODO do some magic
|
for (int i = 0; i < length; i++) {
|
||||||
|
char currentChar = input[i];
|
||||||
|
if (currentChar != delimeter) {
|
||||||
|
tmp[nthChar] = input[i];
|
||||||
|
nthChar++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
char *end;
|
||||||
|
tmp[nthChar] = '\0';
|
||||||
|
result[nthInt] = (int) strtol(tmp, &end, 10);
|
||||||
|
nthChar = 0;
|
||||||
|
memset(&tmp[0], 0, sizeof(tmp));
|
||||||
|
nthInt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -450,9 +458,8 @@ void showFile(String fileName)
|
|||||||
int pixelsLength = readStringLength;
|
int pixelsLength = readStringLength;
|
||||||
|
|
||||||
// parse dimensions and pixels
|
// parse dimensions and pixels
|
||||||
// TODO is there some kind of explode? - that is exactly what we need
|
const int* dimensionsInt = explodeString(dimensions, dimensionsLength, ',');
|
||||||
const int* dimensionsInt = explodeString(dimensions, dimensionsLength);
|
const int* pixelsInt = explodeString(pixels, pixelsLength, ',');
|
||||||
const int* pixelsInt = explodeString(pixels, pixelsLength);
|
|
||||||
// calculate x and y start positions
|
// calculate x and y start positions
|
||||||
int rows = dimensionsInt[0];
|
int rows = dimensionsInt[0];
|
||||||
int cols = dimensionsInt[1];
|
int cols = dimensionsInt[1];
|
||||||
|
|||||||
Reference in New Issue
Block a user