Rev | Line | |
---|
[483] | 1 | define([ |
---|
| 2 | "dojo/_base/lang", |
---|
| 3 | "dojo/_base/sniff" |
---|
| 4 | ], function(lang, has){ |
---|
| 5 | var tokenize = lang.getObject("dojox.string", true).tokenize; |
---|
| 6 | |
---|
| 7 | tokenize = function(/*String*/ str, /*RegExp*/ re, /*Function?*/ parseDelim, /*Object?*/ instance){ |
---|
| 8 | // summary: |
---|
| 9 | // Split a string by a regular expression with the ability to capture the delimeters |
---|
| 10 | // parseDelim: |
---|
| 11 | // Each group (excluding the 0 group) is passed as a parameter. If the function returns |
---|
| 12 | // a value, it's added to the list of tokens. |
---|
| 13 | // instance: |
---|
| 14 | // Used as the "this" instance when calling parseDelim |
---|
| 15 | var tokens = []; |
---|
| 16 | var match, content, lastIndex = 0; |
---|
| 17 | while(match = re.exec(str)){ |
---|
| 18 | content = str.slice(lastIndex, re.lastIndex - match[0].length); |
---|
| 19 | if(content.length){ |
---|
| 20 | tokens.push(content); |
---|
| 21 | } |
---|
| 22 | if(parseDelim){ |
---|
| 23 | if(has("opera")){ |
---|
| 24 | var copy = match.slice(0); |
---|
| 25 | while(copy.length < match.length){ |
---|
| 26 | copy.push(null); |
---|
| 27 | } |
---|
| 28 | match = copy; |
---|
| 29 | } |
---|
| 30 | var parsed = parseDelim.apply(instance, match.slice(1).concat(tokens.length)); |
---|
| 31 | if(typeof parsed != "undefined"){ |
---|
| 32 | tokens.push(parsed); |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | lastIndex = re.lastIndex; |
---|
| 36 | } |
---|
| 37 | content = str.slice(lastIndex); |
---|
| 38 | if(content.length){ |
---|
| 39 | tokens.push(content); |
---|
| 40 | } |
---|
| 41 | return tokens; |
---|
| 42 | }; |
---|
| 43 | return tokenize; |
---|
| 44 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.