View/Edit #29:word_start

Switch to edit mode.

Name(s): word_start
1:  "This breaks up the argument string into words, returning a list of indices into argstr corresponding to the starting points of each of the arguments."
2:  rest = args[1]
3:  "... find first nonspace..."
4:  wstart = match(rest, "[^ ]|$")[$][1]
5:  wbefore = wstart - 1
6:  rest[1..wbefore] = ""
7:  if (!rest)
8:    return {}
9:  endif
10: quote = 0
11: wslist = {}
12: pattern = " +|\\.?|\""
13: while (m = match(rest, pattern))
14:   "... find the next occurence of a special character, either"
15:   "... a block of spaces, a quote or a backslash escape sequence..."
16:   char = m[$][3][1]
17:   if (char == " ")
18:     wslist = {@wslist, {wstart, wbefore + m[$][1] - 1}}
19:     wstart = wbefore + m[$][2] + 1
20:   elseif (char == "\"")
21:     "... beginning or end of quoted string..."
22:     "... within a quoted string spaces aren't special..."
23:     pattern = (quote = !quote) ? "\\.?|\"" | " +|\\.?|\""
24:   endif
25:   rest[1..m[$][2]] = ""
26:   wbefore = wbefore + m[$][2]
27: endwhile
28: return rest || char != " " ? {@wslist, {wstart, wbefore + length(rest)}} | wslist
29: "Last modified by whiz (#3135) on Tue Apr  8 22:51:25 2008 EDT."

Verb arguments: this none this
Verb perms: Readable eXecutable NOT-Debug
Verb owned by: Hacker (#60)

You are not logged in.

[home | help | who | search | setup | code]