diff.tin 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #nop 两个字符串参数,其中一个比另一个多包含了一个子串,本函数可返回该子串(即任务信息);
  2. #func {diff} {
  3. #local str1 {%1};
  4. #local str2 {%2};
  5. #list str1 {tokenize} {$str1};
  6. #list str2 {tokenize} {$str2};
  7. #local size1 {&str1[]};
  8. #local size2 {&str2[]};
  9. #if { $size1 < $size2 } {
  10. #local tmp {$str1};
  11. #local str1 {$str2};
  12. #local str2 {$tmp};
  13. #local tmp {$size1};
  14. #local size1 {$size2};
  15. #local size2 {$tmp};
  16. };
  17. #local idx {};
  18. #loop {1} {$size2} {idx} {
  19. #local ch1 {$str1[$idx]};
  20. #local ch2 {$str2[$idx]};
  21. #if { "$ch1" != "$ch2" } {
  22. #break;
  23. };
  24. };
  25. #local begin {$idx};
  26. #local end {};
  27. #math end {$size1 - $size2 + $begin - 1};
  28. #local diff {};
  29. #loop {$begin} {$end} {idx} {
  30. #local ch {$str1[$idx]};
  31. #cat diff {$ch};
  32. };
  33. #return {$diff};
  34. };
  35. /*
  36. #alias {diff.test} {
  37. #local str1 {洞中无丝毫光亮,脚华山的练功房下平整,便似走在石板路上一般。};
  38. #local str2 {洞中无丝毫光亮,脚下平整,便似走在石板路上一般。};
  39. #echo {STR1: $str1};
  40. #echo {STR2: $str2};
  41. #local diff {@diff{{$str1};{$str2}}};
  42. #nop 会得到「华山的练功房」
  43. #echo {DIFF: $diff};
  44. };
  45. */