absolute_string.sf 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/ruby
  2. # The old problem of string expanding
  3. # https://trizenx.blogspot.ro/2012/03/expand-string.html
  4. func abs_str (str) {
  5. var strs = [];
  6. var root = [];
  7. var word = '';
  8. func store {
  9. word != '' && (
  10. strs.append(root.join + word);
  11. );
  12. }
  13. str.split('').each { |c|
  14. given (c) {
  15. when ('{') {
  16. root.append(word);
  17. word.clear!;
  18. }
  19. when ('}') {
  20. store.run;
  21. root.pop;
  22. word.clear!;
  23. }
  24. when (',') {
  25. store.run;
  26. word.clear!;
  27. }
  28. default {
  29. word += c;
  30. }
  31. }
  32. }
  33. store.run;
  34. return(strs);
  35. }
  36. var strings = [
  37. "perl-{gnome2-wnck,gtk2-{imageview,unique},x11-protocol,image-exiftool}",
  38. "perl-{proc-{simple,processtable},net-{dbus,dropbox-api},goo-canvas}",
  39. "perl-{sort-naturally,json,json-xs,xml-simple,www-mechanize,locale-gettext}",
  40. "perl-{file-{which,basedir,copy-recursive},pathtools,path-class},mplayer",
  41. "perl-{script-{test,meta}},flash-player",
  42. ];
  43. strings.each { |str|
  44. var array = abs_str(str);
  45. "%-25s" * 3 + "\n" -> printf(array[0..2 -> to_list]);
  46. }