-3

Is there a light-weight library for this?

I'm use node.js to parse url log file, but I found it's slow by it's default module querystring and tj's qs.

So I wonder if there is a C++ library to parse the url (better to json string directly) and it's light-weight enough to compile to a node C++ addon.

qs.parse('/?0=foo')
qs.parse('/?a[>=]=23')
qs.parse('/?foo=bar&baz')
qs.parse('/?a[b][c]=d')
qs.parse('/?a[b][c][d]=e')
qs.parse('/?a=b&a=c')
qs.parse('/?a[]=b')
qs.parse('/?a[]=b&a[]=c&a[]=d')
qs.parse('/?a=b&a[]=c')
qs.parse('/?a[]=b&a=c')
qs.parse('/?a=b&a[0]=c')
qs.parse('/?a=b&a[1]=c')
qs.parse('/?a[b][]=c&a[b][]=d')
qs.parse('/?a[1]=c&a[0]=b&a[2]=d')
qs.parse('/?a[1]=c&a[0]=b')
qs.parse('/?a[20]=a')
qs.parse('/?a[12b]=c')
qs.parse('/?he%3Dllo=th%3Dere')
qs.parse('/?a[b]=c%20d')
qs.parse('/?foo[0]=bar&foo[bad]=baz')
qs.parse('/?foo[bad]=baz&foo[0]=bar')
qs.parse('/?foo[]=bar&foo[bad]=baz')
qs.parse('/?foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb')
qs.parse('/?a[]=b&a[t]=u&a[hasOwnProperty]=c')
qs.parse('/?foo[0].baz=bar&fool.bad=baz')
// ...

well, can you feel my problem?

Lellansin
  • 852
  • 1
  • 9
  • 15
  • This answer may be helpful: https://stackoverflow.com/questions/28268236/parse-http-request-without-using-regexp/28269049#28269049 – Galik Apr 19 '16 at 04:29
  • [Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.](http://stackoverflow.com/help/on-topic) – rsjaffe Apr 19 '16 at 04:34
  • Thx @Galik , do you know array and object type url param? Such as "foo[bar]=baz", "a[0]=b&a[1]=&a[2]=c" etc.. – Lellansin Apr 19 '16 at 05:43
  • @RoryJaffe Which book, tool, software library, tutorial do you mean? I'm green in C++, it's better if you can give some, well, even one keyword for my problem, thanks. – Lellansin Apr 19 '16 at 05:54
  • So, do you want to parse in JS and then passing the result into a native module or directly in C++? –  Apr 19 '16 at 06:01
  • @JasonWihardja node's http module get the http headers such as : "/?foo[bad]=baz&foo[0]=bar", and using C++ to parse it into json string, like { "foo": { "bad": "baz", "0": "bar" } }, and return to node.js. This produce is slow by js. – Lellansin Apr 19 '16 at 06:13
  • What about something like https://stackoverflow.com/a/63181227/2193968 – Jerry Jeremiah Jul 30 '20 at 21:57

1 Answers1

2

You can use cpp-netlib library and in particular the URI class (boost::network::http::uri). More information here.

Francesco Argese
  • 626
  • 4
  • 11