test-pcre2.nut 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //auto str = " this code 10.89.973.8.3.00.34-8 is special 23.456-2 car";
  2. auto str = " this code 10.89.973.8.3.00.34/8 is special 23.456/2 car";
  3. //print("loadlib", sqpcre.loadlib("/home/mingo/dev/c/A_libs/pcre-8.38/.libs/libpcre.so.1.2.6"));
  4. print("loadlib", sqpcre2.loadlib("/home/mingo/dev/c/A_libs/pcre2-10.20/.libs/libpcre2-8.so"));
  5. local function mycallout(cb_idx, cb_str, start_match, current_position, p)
  6. {
  7. print("mycallout", cb_idx, cb_str, start_match, current_position, p);
  8. return 0;
  9. }
  10. //auto pcre = sqpcre(@"(\d+[.,\-])+\d+");
  11. //auto pcre = sqpcre(@"(?:\d+[.,\-/])+\d+");
  12. auto pcre = sqpcre2(@"(?:\d+[.,\-/]\n*)+(?C'number found')\d+");
  13. pcre.set_callout(mycallout, "myparam");
  14. print(pcre, typeof(pcre));
  15. print(pcre.version());
  16. pcre.set_callout_param(str);
  17. print("match", pcre.match(str));
  18. pcre.gmatch(str,
  19. function(...){
  20. print("gmatch vargv.len()", vargv.len());
  21. foreach(idx, elm in vargv) print(idx, elm);
  22. return true;
  23. });
  24. auto new_str = pcre.gsub(str, "@$0@");
  25. print(new_str);
  26. auto result = [];
  27. auto rc, start_pos;
  28. auto max_loop = 1;
  29. auto start_time = os.getmillicount();
  30. for(auto i=0; i < max_loop; ++i)
  31. {
  32. start_pos = 0;
  33. while( (rc = pcre.exec(str, result, start_pos)) > 0)
  34. {
  35. print(rc, result.len());
  36. if(rc > 0)
  37. {
  38. //foreach(idx, elm in result)
  39. print(str.slice(result[0], result[1]));
  40. start_pos = result[1] + 1;
  41. }
  42. }
  43. }
  44. print("Spent time", os.getmillicount() - start_time);
  45. /*
  46. start_time = os.getmillicount();
  47. for(auto i=0; i < max_loop; ++i)
  48. {
  49. start_pos = 0;
  50. while( (rc = str.find_lua("(%d[,.%-])", result, start_pos)) > 0)
  51. {
  52. print(rc, result.len());
  53. if(rc > 0)
  54. {
  55. foreach(idx, elm in result) print(idx, elm, str.slice(result[0], result[1]));
  56. start_pos = result[1] + 1;
  57. }
  58. }
  59. }
  60. print("Spent time", os.getmillicount() - start_time);
  61. */