Class: Groonga::Command::Parser::CommandLineSplitter
- Inherits:
-
Object
- Object
- Groonga::Command::Parser::CommandLineSplitter
- Defined in:
- lib/groonga/command/parser/command-line-splitter.rb
Instance Method Summary collapse
-
#initialize(command_line) ⇒ CommandLineSplitter
constructor
A new instance of CommandLineSplitter.
- #split ⇒ Object
Constructor Details
#initialize(command_line) ⇒ CommandLineSplitter
Returns a new instance of CommandLineSplitter.
24 25 26 |
# File 'lib/groonga/command/parser/command-line-splitter.rb', line 24 def initialize(command_line) @command_line = command_line end |
Instance Method Details
#split ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/groonga/command/parser/command-line-splitter.rb', line 28 def split tokens = [] scanner = StringScanner.new(@command_line) skip_spaces(scanner) start_quote = nil until scanner.eos? if start_quote token = "" loop do chunk = scanner.scan_until(/#{Regexp.escape(start_quote)}/) if chunk.nil? token = start_quote + token + scanner.rest scanner.terminate break end if chunk[-2] == "\\" token << chunk else token << chunk.chomp(start_quote) break end end tokens << unescape(token) start_quote = nil skip_spaces(scanner) else start_quote = scanner.scan(/['"]/) if start_quote.nil? tokens << scanner.scan_until(/\S+/) skip_spaces(scanner) end end end tokens end |