[redland-dev] C# binding encoding problem
Victor Lindesay
victor at schemaweb.info
Thu Sep 23 14:09:55 BST 2004
Hi Edd,
Thanks for your replies.
I have made a little progress with my Redland problems.
> > For example, without these changes, stepping through the C code I
> > notice that if I create a "rdfxml" parser, the line:
> > if(!strcmp(syntax_name, "rdfxml")) { ... in
> > librdf_parser_raptor_constructor() fails.
>
> Hmm, this is interesting but not necessarily wrong. The *Auto
> methods marshal to and from Unicode on Windows. You can't
> use strcmp against Unicode strings and expect it to work,
> except with UTF-8 encoded strings that only contain ASCII characters.
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:
For example:
Old example:
[DllImport ("librdf")]
static extern IntPtr librdf_new_parser (IntPtr world, IntPtr name,
IntPtr mime_type, IntPtr uri); private Parser (World world, string
name, string mime_type, Uri uri) {
IntPtr iname = Marshal.StringToHGlobalAuto (name);
IntPtr imime_type = Marshal.StringToHGlobalAuto (mime_type);
if (uri == (Uri) null)
parser = librdf_new_parser (world.Handle, iname,
imime_type, IntPtr.Zero);
else
parser = librdf_new_parser (world.Handle, iname,
imime_type, uri.Handle);
Marshal.FreeHGlobal (iname);
Marshal.FreeHGlobal (imime_type);
}
New examples:
[DllImport ("librdf")]
static extern IntPtr librdf_new_parser (IntPtr world,
[MarshalAs(UnmanagedType.LPStr)] string name,
[MarshalAs(UnmanagedType.LPStr)] string mime_type, IntPtr uri);
private Parser (World world, string name, string mime_type, Uri uri) {
if (uri == (Uri) null)
parser = librdf_new_parser (world.Handle, name,
mime_type, IntPtr.Zero);
else
parser = librdf_new_parser (world.Handle, name,
mime_type, uri.Handle); }
and
[DllImport ("librdf")]
[return: MarshalAs(UnmanagedType.LPStr)]
static extern string librdf_node_to_string (IntPtr node);
public override string ToString ()
{
return librdf_node_to_string (node);
}
No luck yet with returned strings with latin-1 chars.
Or passing the RDF in as a string even with the above changes.
For López I am getting the following bytes from the above
Node.ToString() method:
[76][195][131][194][179][112][101][122]
I presume that [195][131][194][179] is the ó char.
I am pressing on and trying to write a .Net function to convert the
Redland output strings.
More information about the redland-dev
mailing list