如何用C语言编写类似jQuery的代码?

如何用C语言编写类似jQuery的代码?,jquery,c++,c,linux,fedora,Jquery,C++,C,Linux,Fedora,如何在C语言中进行类似jQuery的调用 假设我们有一个数据包(例如html): 但是在C语言中,我怎么能做这样的事情呢?(不是如何解析字符串,而是如何实现这样的函数().function().function().function().fundle…().fundle() 主要条款c: int main () { "This is a html string".cWayFind("is").cWayFind("etc etc").cWayModify(properties, tonewProp

如何在C语言中进行类似jQuery的调用

假设我们有一个数据包(例如html):

但是在C语言中,我怎么能做这样的事情呢?(不是如何解析字符串,而是如何实现这样的函数().function().function().function().fundle…().fundle()

主要条款c:

int
main () {
"This is a html string".cWayFind("is").cWayFind("etc etc").cWayModify(properties, tonewProperties);

 return 0;
}

这里是一个很好的起点:


你可能想使用C++。在那里,很容易从一个可以引用相同基础数据的函数返回一个对象。
 struct DOMNode {
      DOMNode Find (const char* name);
 };
您可以立即键入
DOMNode().Find(“foo”).Find(“bar”);
,无需特殊魔法

如果要修改对象本身,只需返回对
this
的引用即可

 struct DOMNode {
      DOMNode& SetAttribute (const char* name, const char* value) { /* ... */; return *this; }
 };

要执行类似的操作,通常需要将接收方,即
this
,作为每个函数调用的第一个参数

cWayModify(cWayFind(cWayFind("This is a html string", "is"), "etc etc"), properties, tonewProperties);

最内层函数调用首先被评估。方法调用的点运算符实际上只是语法糖,使代码更可读;第一个被评估的动作首先出现在链式代码行中。

< p>您需要一个C++实现的jQuery类型解析器。在这一点上我不知道存在什么。

我想你是什么?我们正在寻找的是能够链接字符串扩展
 struct DOMNode {
      DOMNode& SetAttribute (const char* name, const char* value) { /* ... */; return *this; }
 };
cWayModify(cWayFind(cWayFind("This is a html string", "is"), "etc etc"), properties, tonewProperties);