[redland-dev] C# binding encoding problem
Edd Dumbill
edd at usefulinc.com
Fri Sep 24 14:28:57 BST 2004
On Thu, 2004-09-23 at 14:09 +0100, Victor Lindesay wrote:
> I have solved the problem creating Storage and Parser objects with
> changes to the function prototypes that have string params or return
> values using MarshalAs attributes instead of InPtr:
...
> [DllImport ("librdf")]
> static extern IntPtr librdf_new_parser (IntPtr world,
> [MarshalAs(UnmanagedType.LPStr)] string name,
> [MarshalAs(UnmanagedType.LPStr)] string mime_type, IntPtr uri);
This might well work, but I don't know if it's the right solution in the
long term. LPStr according to .NET docs is an "ANSI string". What
Microsoft mean by that seems to be something encoded in windows-cp-1252.
This is the same effect as the changes from *Auto to *Ansi that you
made, but obviously nicer syntactically. I am concerned that this won't
work the same on Mono.
Ideally we'd use enumerations here to ensure that the API user doesn't
have to pass strings to get the type of parser or storage they want.
Dave says "all redland strings are utf8 unless otherwise stated". So I
think we'd be safe to ensure that all the strings are marshalled not to
ANSI strings, but to UTF-8 encoding.
As for your other issues, when triples are added programmatically to
Redland, UTF-8 is assumed as the default encoding. This is why
librdf_parser_parse_string_into_model() fails for you on the Latin-1
chars.
When you output a model again, you get UTF-8.
-- Edd
More information about the redland-dev
mailing list