string - What's the fastest/most efficient way to count lines in Rebol? -
given string string
, fastest/most-efficient way count lines therein? take best answers flavour of rebol. i've been working under assumption parse [some [thru]]
combination fastest way traverse string, don't know certain, hence turning so:
count-lines: func [string [string!] /local count][ parse/all string [ (count: 1) [thru newline (count: count + 1)] ] count ]
or:
count-lines: func [string [string!] /local count][ count: 0 until [ count: count + 1 not string: find/tail string newline ] count ]
and how counters? how efficient repeat?
count-lines: func [string [string!]][ repeat count length? string [ unless string: find/tail string newline [ break/return count ] ] ]
update: line count goes text editor principle:
an empty document still has line count of one. so:
>> count-lines "" == 1 >> count-lines "^/" == 2
count-lines: func [ str /local sort-str ][ sort-str: sort bring together str "^/" 1 + subtract index? find/last sort-str "^/" index? find sort-str "^/" ]
string performance newline rebol
No comments:
Post a Comment