You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The condition "if sizeOfFile(MACROS_LOG_FILE) = 0 then" is checking if the log file is empty before appending the new record. This can lead to an additional read of the file to check the size, which can be inefficient for large files. An alternative would be to keep a separate counter or use a global variable to check if this is the first time a record is being added and then add the log header if so.
const
HtmlEncodeChars: array[0..4] ofrecord
Char: Char;
Code: string;
end = (
(Char: '<'; Code: '<'),
(Char: '>'; Code: '>'),
(Char: '&'; Code: '&'),
(Char: '"'; Code: '"'),
(Char: ''''; Code: ''')
);
functionhtmlEncode(const s: string): string;
var
i, j, len: integer;
begin
len := Length(s);
SetLength(Result, len * 6); // máximo tamanho possível após a conversão
j := 1;
for i := 1to len dobeginif s[i] < ''then// caracteres de controlebegin
Result[j] := '?';
Inc(j);
endelsebegincase s[i] of'<', '>', '&', '"', '''':
begin
Move(PChar(HtmlEncodeChars[s[i] = '<']).^, PChar(@Result[j])^, Length(HtmlEncodeChars[s[i] = '<']) * SizeOf(HtmlEncodeChars[0]));
Inc(j, Length(HtmlEncodeChars[s[i] = '<']));
end;
else
Result[j] := s[i];
Inc(j);
end;
end;
end;
SetLength(Result, j - 1);
end;
Create a constant called HtmlEncodeChars that contains a list of HTML characters and their HTML encoded equivalents.
I've defined an htmlEncode function that iterates through the characters in the input string, checks whether each character needs to be HTML-encoded, and then adds the encoded character to the result. This is done using the Move function to copy the corresponding HTML code into the result.
If the macrosLog method is called frequently over a short period of time, it can be useful to group multiple log entries into a single write to disk.
This can be done by adding a global variable that stores the last write time to disk and then checking that a sufficient amount of time has passed since the last disk write before writing the new log entry.
The text was updated successfully, but these errors were encountered:
hey Carlos,
I forgot to write on the first page that this project is not actively developed anymore.
I started a completely new project an another repository. https://github.com/rejetto/hfs
The condition "if sizeOfFile(MACROS_LOG_FILE) = 0 then" is checking if the log file is empty before appending the new record. This can lead to an additional read of the file to check the size, which can be inefficient for large files. An alternative would be to keep a separate counter or use a global variable to check if this is the first time a record is being added and then add the log header if so.
Create a constant called HtmlEncodeChars that contains a list of HTML characters and their HTML encoded equivalents.
I've defined an htmlEncode function that iterates through the characters in the input string, checks whether each character needs to be HTML-encoded, and then adds the encoded character to the result. This is done using the Move function to copy the corresponding HTML code into the result.
If the macrosLog method is called frequently over a short period of time, it can be useful to group multiple log entries into a single write to disk.
This can be done by adding a global variable that stores the last write time to disk and then checking that a sufficient amount of time has passed since the last disk write before writing the new log entry.
The text was updated successfully, but these errors were encountered: