Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions entries/rlawson/src/parser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ implementation
BUFFER_SIZE = READ_SIZE + 1024;
REC_SEP: char = ';';
LF: char = chr(10);
ANSI_ZERO: integer = 48;
DECIMAL_POINT: char = '.';
NEGATIVE_SIGN: char = '-';

Expand All @@ -47,6 +46,7 @@ procedure ProcessMeasurements(var buffer: array of char; bufferLength: integer;
// read the city by looking for semicolon
city := '';
cityStart := idx;
Inc(idx); // city has to be at least one character
while buffer[idx] <> REC_SEP do Inc(idx);
SetString(city, @buffer[cityStart], (idx - cityStart));
// parse the temp reading
Expand All @@ -58,17 +58,20 @@ procedure ProcessMeasurements(var buffer: array of char; bufferLength: integer;
currentTempSign := -1;
Inc(idx);
end;
// look ahead - is decimal point 2 spaces away then we have two digits
// look ahead - is decimal point 2 spaces away then we have temp = dd.d
// other wise d.d
temp := 0;
if buffer[idx + 2] = DECIMAL_POINT then
begin
temp := 100 * (byte(buffer[idx]) - ANSI_ZERO);
Inc(idx);
temp := currentTempSign * (100 * Integer(buffer[idx]) + 10 *
Integer(buffer[idx + 1]) + Integer(buffer[idx + 3]) - 5328);
idx := idx + 6;
end
else
begin
temp := currentTempSign * (10 * Integer(buffer[idx]) + Integer(buffer[idx + 2]) - 528);
idx := idx + 5;
end;
temp := temp + 10 * (byte(buffer[idx]) - ANSI_ZERO);
idx := idx + 2;
temp := currentTempSign * (temp + (byte(buffer[idx]) - ANSI_ZERO));
idx := idx + 3;
reading := results.Find(city);
if reading = nil then
begin
Expand Down