How to do jQuery like calls in C language?
Say we have a packets (html for example):
<div id="mymute">
<div>
</div>
<div>
<img src="/agents/sleeping.png" />
</div>
<div>
</div>
</div>
Javascript/Jquery it query that packets and find the image tag and update the src attribute. using simply like this:
$('#mymute').find('div').find('img').attr('src','/agents/wakeUP.png');
But in C how can i do something like this? (not how to parse a string but how to implement such function().function().function().function().endless...().endless()?
main.c:
int
main () {
"This is a html string".cWayFind("is").cWayFind("etc etc").cWayModify(properties, tonewProperties);
return 0;
}
You probably want to use C++. There, it's very easy to return an object from a function which can reference the same underlying data. Ie if you have something like
struct DOMNode {
DOMNode Find (const char* name);
};
you can immediately type DOMNode ().Find("foo").Find("bar");
, no special magic required.
If you want to modify the object itself, just return a reference to this
.
struct DOMNode {
DOMNode& SetAttribute (const char* name, const char* value) { /* ... */; return *this; }
};
Here's a great place to start:
You need a jQuery type parser implemented in C++. At this point I do not know of any that exists.
To do something like this usually you pass the receiver, ie this
, as the first argument to each function call.
cWayModify(cWayFind(cWayFind("This is a html string", "is"), "etc etc"), properties, tonewProperties);
The most inner function call is evaluated first. The dot operator for method call is really just syntactic sugar to make the code more readable; The first action that is evaluated occurs first in a chained line of code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.