How to get a string from an xcb_atom_t? - x11

I want to find out the name of an xcb_randr_monitor_info_t. It has a name field, but that's of type xcb_atom_t, not a char [255] or something easy like that. How can I turn it into a (preferably UTF-8) string?

You are looking for xcb_get_atom_name_name
xcb_get_atom_name_reply_t *reply=xcb_get_atom_name_reply(
dis, xcb_get_atom_name(dis, atom), NULL);
char*name=xcb_get_atom_name_name(reply);

Related

Packet field enumeration as string

I would like to get the string representation of a packet field, something like:
pkt[BOOTP].op == 'BOOTREPLY'
So far, the only cumbersome way I found is:
pkt[BOOTP].fields_desc[0].i2repr(pkt[BOOTP], 2)
Any other idea?
You can use sprintf
pkt.sprintf("%BOOTP.op%")

Freemarker - default value for variable that may be missing or blank?

In Freemarker, I want to treat something that may be missing (not defined on given object or in given Map), have a null value, be an empty string "" or a string with whitespace only (" \t\n"), AKA blank string. Or a real value like "foo".
In case it's anything besides a non-blank string, I want the expression to return a default value.
How can I handle this in Freemarker?
So far, this is what I use:
${ obj.propery???then(obj.property?trim!"default") }
But I can imagine something more ellegant, like
${ obj.property!!?trim!"default" }
and even with trimming (which is quite common operation for templates):
${ obj.property!!!"default" }
Is there something such in Freemarker? (Besides coding my own method or macro.)
There's nothing in FreeMarker for that, at least not in 2.3.24. I think the best way to address that is wiriting a trimToNull function, and then you can write trimToNull(obj.property)!"default" and trimToNull(obj.property)??, etc.
I had the same challenge and came to this solution:
${ (obj.property!"")?trim }
It also trims the empty string but is easier to read than writing an function or a if.

How to evaluate a string in its template with given values in ruby

there is a string like this and it is stored in a file
#{date}abcde.doc
I want to be able to read this string and replace #{date} with
Date.today.strftime("%Y%m%d")
Is there any way to parse the template and do the evaluation? Thanks in advance!
Yes, however...
It would be easier if you used hash replacement, like this:
s = "%{date}abcde.doc"
s % { date: Time.now.strftime(etc) }
Or just use ERb.
As-is you're using string interpolation so it would need to be evaled, I think.

How to search a string within another string in Visual C++?

I want to need to find a string, replace the string by another string.
For example, replace 'apple' to 'orange' in the following string.
"I love apple"
What function should I use?
Thanks
Since this question is tagged C++/CLI, I'm assuming you're referring to managed String objects.
If so, then there's a Replace method on the String class you can use.
String^ orig = "I love apple";
String^ modified = orig->Replace("apple", "orange");

Regular Expression for text in between tags

I have a QString that I need to parse. This QString is a QNetworkReply object obtained from an URL.
<label id='Today_LastSale1'>$ 21.2401</label>
I need the value 21.2401 from the QString.
I am tried this.
QRegExp rx("<label id='Today_LastSale1'>$ (\\d)</label>");
But it returns -1. Need help with this.
Thanks in Advance!
You can just try to remove the non-numeric and "." characters from your string. Try regex replace with this expression: "[^0-9\.]"
Code
QRegExp rx("[^0-9\\.]");
yourString.replace(rx, "");

Resources