IRC channel logs
2023-05-06.log
back to list of logs
<daviid>in the context i need this, the content of the array is actually a template.ui file content, so the content of an xml file - how do/should i open a .ui file in scheme, so what i get is an array of guint8 [uint8] <RhodiumToad>the file is expected to be small, or at least fitting reasonably into memory? <daviid>RhodiumToad: ok, what about the encoding? <RhodiumToad>i.e. open the file as a port, get the content as a bytevector, then you can get a C pointer that points to the bytevector content <daviid>the xml file is full of strings ... <daviid>*maybe full of translatable strings - somewhere i did read they expect utf8 <RhodiumToad>i.e. whatever you end up passing the GBytes to, is presumably expecting the data to be in some encoding? <daviid>it's a bit confusing, but of course the template will then be used by the application that derives the GObject type, so it will be 'transformed' ack to what ever it needs to define and present, say, labels for example ... <daviid>so, though they want a GBytes, full of uint8, in the end, the'll decode it and prsent the strings to gtk/adwata ... <RhodiumToad>and xml can contain its own charset declaration, are they going to recognize that? <daviid>so, i guess i need to open the file specifying utf8, then call get-bytevector-all? did i understood correctly your suggestion? <RhodiumToad>I would open the file in binary mode, not specifying utf8 as such <daviid>ok, i am a bit confused becaue of the encoding <RhodiumToad>from what I'm seeing, the file is essentially part of the app, yes? rather than user-supplied data <daviid>i mean becaue the inadequacy between uint8 and the fact that the xml file is encoded in utf8 <RhodiumToad>so it's the responsibility of the creator to get the encoding right <daviid>well, g-golf users will of course define their templates ... <daviid>as an example, the adwaita1 demo, produced by the adwaita team of course, starts with "<?xml version="1.0" encoding="UTF-8"?> <interface> ... <template class="AdwDemoWindow" parent="AdwApplicationWindow"> ... ... ... </template> </interface> <RhodiumToad>the interface seems, from the docs you linked, to be expecting to get just the raw bytes <RhodiumToad>guint8 is just an unsigned char, you don't have to sweat the difference between signed and unsigned char types, they're all just bytes <daviid>ok pefect, i forgot how to open a file in binary mode <daviid>RhodiumToad: thanks! i'll figure it out <RhodiumToad>(call-with-input-file filename (lambda (port) (get-bytevector-all port)) #:binary #t) <daviid>RhodiumToad: many thanks, it's gona a take a bit more time before i have it workong in g-golf, but will let you know ... <lloda>all #:binary does is set encoding to iso-8859-1. That only matters if you're reading text, funnily enough. It doesn't do anything if you're reading bytes <lloda>imo this parameter should be deprecated in all the port functions <lloda>the manual mentions unget-byte, which doesn't exist. There is get-u8, so maybe we need unget-u8 <daviid>lloda: ok, thanks [for these info] <RhodiumToad>what's the best way to remove an optional prefix from a string? e.g. given "foo:bar" return "bar", but given "baz" return it unchanged <RhodiumToad>(if (string-prefix? pfx str) (string-drop str (string-length pfx)) str)) is the obvious way, not sure if there's a better one <old>RhodiumToad: (lambda (prefix string) (string-drop (string-prefix-length prefix string))) ? <old>no need for the predicate I think <daviid>and if : is (always) the sep, no need for prefix either <RhodiumToad>that's not quite what I want; it'll drop characters on a partial match <RhodiumToad>I could look for the : but I'm not sure that makes it easier? <old>(lambda (prefix string) (let ((expected-length (string-length prefix))) (when (= expected-length (string-prefix-length prefix string)) (string-drop string expected-length)))) <daviid>a lot easier, but you said partial match ... <old>it's equivalent I think <old>more verbose that's for sure <RhodiumToad>did you forget to return the string unchanged when the prefix is not there? <RhodiumToad>daviid: it's ok in this case to assume that the prefix will end with : and that : doesn't appear outside the prefix <daviid>or (and=> (string-index str #\:) <daviid> (lambda (index) (string-drop str (1+ index)))) <daviid>properly indented it looks better :)