[fpc-pascal] TMaskUtils.ValidateInput function: how is it supposed to behave?
Bart
bartjunk64 at gmail.com
Mon Apr 18 18:47:48 CEST 2016
On 4/18/16, Michael Van Canneyt <michael at freepascal.org> wrote:
> I think Bart meant that the maskutils unit should simply use unicodestring.
> Given that it almost surely will need to deal with $ and € etc, that seems
> like a better approach.
Yep.
In UTF8 the 1 on 1 relation between the internal mask structure and
the content of Value gets lost.
In LCL's MaskEdit unit this is solved by assuming all string data is UTF8.
(We convert the result from the widgetset to UTF8 explicitely)
The MaskEdit unit has routines (GetCodePoint/SetCodePoint) that rely
on routines in LazUtf8 in order to match a position of a codepoint to
a position in the internal mask.
This cannot be done in pure fpc, so a TMaskUtils based on AnsiChar can
only function with single byte encoding (as it is now, so that doesn't
break anything)..
(UTF8 might even work if no case conversion is used in the mask, I
have not tested).
I attach an alterative _maskutils unit, which basically uses the same
approach as TMaskEdit, but without the UTF8 support.
Rewriting this to use WideChar and UnicodeString should be very easy.
The internal processing of the (edit)mask is the same as TMaskEdit.
If that is broken somehow, it is also broken in TMaskEdit.
The only functions that may need adjustments are
* function FormatMaskText(const EditMask: string; const AValue: string): string;
* function FormatMaskInput(const EditMask: string): string;
* function MaskDoFormatText(const EditMask: string; const AValue: string;
ASpaceChar: Char): string;
* function TMaskUtils.TryValidateInput(out ValidatedString: String): Boolean;
But since there is no real documentation and there is no test suite,
it's hard to tell if they do not function as they should or introduce
regressions.
Note; I did not find any reference to use of MaskUtils in FreePascal
itself, except for the uses clause in the db uit (where I did not find
any reference to the above mentioned functions).
Q: Would changing the implementation to UnicodeString introduce
regressions or compilation errors for existing programs using this
unit?
(It'll probably give warnings about possible data loss due to implicit
conversions.)
Bart
-------------- next part --------------
A non-text attachment was scrubbed...
Name: _maskutils.pas
Type: text/x-pascal
Size: 28591 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20160418/6d31d630/attachment.pas>
More information about the fpc-pascal
mailing list