[m-rev.] diff: implement some formatting functions for .NET
Peter Ross
peter.ross at miscrit.be
Tue Aug 28 19:44:57 AEST 2001
On Tue, Aug 28, 2001 at 11:35:09AM +0200, Tyson Dowd wrote:
> Hi,
>
> My aim was to get error/1 exceptions to print correctly, but I also
> tried to get some of tests/general/string_format_test.m to work.
>
> ===================================================================
>
>
> Estimated hours taken: 5
> Branches: main
>
> library/string.m:
> Implement string__append_list and various formatting functions
> in C#.
> Implement a very simple (and incomplete) conversion of printf style
> formatting to .NET formatting. It is probably a better idea to
> implement printf formatting in Mercury in future, as neither
> .NET nor Java provides printf.
>
> runtime/mercury_mcpp.cpp:
> Add some code to manipulate Mercury lists in the low-level data
> representation.
>
>
> Index: library/string.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/string.m,v
> retrieving revision 1.154
> diff -u -r1.154 string.m
> --- library/string.m 2001/08/14 10:18:50 1.154
> +++ library/string.m 2001/08/27 15:30:10
> @@ -1020,11 +1020,18 @@
> }").
>
> :- pragma foreign_proc("C#",
> - string__append_list(_Strs::in) = (_Str::uo),
> - [will_not_call_mercury, thread_safe], "{
> - mercury.runtime.Errors.SORRY(""foreign code for this function"");
> - _Str = null;
> -}").
> + string__append_list(Strs::in) = (Str::uo),
> + [will_not_call_mercury, thread_safe], "
> +{
> + System.Text.StringBuilder tmp = new System.Text.StringBuilder();
> +
> + while (mercury.runtime.LowLevelData.list_is_cons(Strs)) {
> + tmp.Append(mercury.runtime.LowLevelData.list_get_head(Strs));
> + Strs = mercury.runtime.LowLevelData.list_get_tail(Strs);
These two lines aren't indented to the same level.
> + }
> + Str = tmp.ToString();
> +}
> +").
>
Also the StringBuilder class only allows one to build a string
efficiently upto some maximum capacity. It *doesn't* dynamically expand
the size of the string. The default capacity according to the
documentation is 16 chars, so this code isn't very robust. What you
should do is count up the length of the string, then allocate a string
builder of the correct size, blah, blah, blah.
Pete
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list