b9488ed09a785de18eeb0739889dd5923b779f93.svn-base 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. if (!dojo._hasResource["dojox.string.tokenize"]) { // _hasResource checks added
  2. // by build. Do not use
  3. // _hasResource directly in
  4. // your code.
  5. dojo._hasResource["dojox.string.tokenize"] = true;
  6. dojo.provide("dojox.string.tokenize");
  7. dojox.string.tokenize = function(/* String */str, /* RegExp */re, /* Function? */
  8. parseDelim, /* Object? */instance) {
  9. // summary:
  10. // Split a string by a regular expression with the ability to capture
  11. // the delimeters
  12. // parseDelim:
  13. // Each group (excluding the 0 group) is passed as a parameter. If the
  14. // function returns
  15. // a value, it's added to the list of tokens.
  16. // instance:
  17. // Used as the "this" instance when calling parseDelim
  18. var tokens = [];
  19. var match, content, lastIndex = 0;
  20. while (match = re.exec(str)) {
  21. content = str.substring(lastIndex, re.lastIndex - match[0].length);
  22. if (content.length) {
  23. tokens.push(content);
  24. }
  25. if (parseDelim) {
  26. var parsed = parseDelim.apply(instance, match.slice(1));
  27. if (typeof parsed != "undefined") {
  28. tokens.push(parsed);
  29. }
  30. }
  31. lastIndex = re.lastIndex;
  32. }
  33. content = str.substr(lastIndex);
  34. if (content.length) {
  35. tokens.push(content);
  36. }
  37. return tokens;
  38. }
  39. }