Advertisement
Bukz

Parsing tools concept

Apr 27th, 2011
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.59 KB | None | 0 0
  1. // This file gets executed every time you start AssaultCube.
  2.  
  3. // This is where you should put any scripts you may have created for AC.
  4.  
  5. // findchar string char int - Returns int
  6. findchar = [
  7.   charposition = -1; dupes = 0
  8.   loop fcl (strlen $arg1) [ if (strcmp (substr $arg1 $fcl 1) $arg2) [ += dupes 1; if (> $dupes $arg3) [ charposition = $fcl; break ] ] ]
  9.   result $charposition
  10. ]
  11. // echo (findchar AssaultCube s 0) // Output: 1
  12. // echo (findchar AssaultCube s 1) // Output: 2
  13. // echo (findchar AssaultCube s 2) // Output: -1
  14. // echo (findchar AssaultCube z 0) // Output: -1
  15.  
  16. // countchar string char - Returns int
  17. countchar = [
  18.   chars = 0
  19.   loop ccl (strlen $arg1) [ if (strcmp (substr $arg1 $ccl 1) $arg2) [ += chars 1 ] ]
  20.   result $chars
  21. ]
  22. // echo (countchar AssaultCube s) // Output: 2
  23. // echo (countchar Mississippi i) // Output: 4
  24. // echo (countchar "lol what!" p) // Output: 0
  25.  
  26. // haschar string char - Returns bool
  27. haschar = [
  28.   bool = 0
  29.   loop ccl (strlen $arg1) [ if (strcmp (substr $arg1 $ccl 1) $arg2) [ bool = 1; break ] ]
  30.   result $bool
  31. ]
  32. // echo (haschar AssaultCube C) // Output: 1
  33. // echo (haschar AssaultCube c) // Output: 0
  34.  
  35. // inschar string string position - Returns string
  36. inschar = [
  37.   output = ""
  38.   if (<= $arg3 (- (strlen $arg1) 1)) [
  39.     loop icl (strlen $arg1) [
  40.       if (= $icl $arg3) [
  41.         output = (concatword $output $arg2 (substr $arg1 $icl 1))
  42.       ] [
  43.         output = (concatword $output (substr $arg1 $icl 1))
  44.       ]
  45.     ]
  46.     result $output
  47.   ] [ result -1 ]
  48. ]
  49. // echo (inschar "hello world" " cruel" 5) // Output: hello cruel world
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement