On 2019-09-16 00:29, DougC wrote:

Doug,

 .
 .
I do not like item 3 in that the function, as described, is named
DetectUtfBom but does more than detect. Side effects of functions are
generally not good. I would at least rename it something like
DetectAndHandleUtfBom.

Take the provided names just as my proposal, I can imagine that there may be better alternatives.


But to fully correct the situation, I would also change it to a
procedure since leaving it as a function still suggests it only
returns a result and has no other side effects.

No, changing it to a procedure would not work - the information whether BOM was found and thus the codepage in the text file record was set accordingly, or whether the information was not available, is very important for further processing (as an example, the programmer may ask the end user to provide information about the text file encoding in such a case). Purely from technical point of view, it would be possible to change it to a procedure and move the return value to a new actual parameter, but it doesn't make much sense from my point of view.

Tomas



---- On Sun, 15 Sep 2019 18:20:22 -0400 Tomas Hajny
<xhaj...@hajny.biz> wrote ----


3) New function 'DetectUtfBom (var T: text): boolean' will be added.
This function may be called after the call to 'Reset (T: text)' to check
for existence of BOM at the beginning of the text file. If it is found
(Result=true), SetTextCodePage is invoked automatically from
DetectUtfBom with the codepage value corresponding to the found BOM and
encoding variant. If BOM is not found (Result=false), nothing changes.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to