bashparser 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/bashparser.rb +49 -2
- metadata +1 -1
data/lib/bashparser.rb
CHANGED
@@ -33,7 +33,55 @@ class BashParser
|
|
33
33
|
get_buffer_contents
|
34
34
|
end
|
35
35
|
|
36
|
+
def save_input_to_file(input, file_name)
|
37
|
+
#used for debugging purposes
|
38
|
+
File.open(file_name, 'w') do |f|
|
39
|
+
input.dup.each_byte do |byte|
|
40
|
+
f.putc(byte)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.seperate_by_escape_codes(input)
|
46
|
+
return_data = []
|
47
|
+
escape_code_list = []
|
48
|
+
input = input + ESCAPE_BYTE.chr #Insures last string is inserted into return_data
|
49
|
+
|
50
|
+
escape_code = INACTIVE
|
51
|
+
string = ''
|
52
|
+
input.each_byte do |byte|
|
53
|
+
char = byte.chr
|
54
|
+
|
55
|
+
if byte == ESCAPE_BYTE
|
56
|
+
escape_code = ''
|
57
|
+
if string != ''
|
58
|
+
return_data << [string, escape_code_list ]
|
59
|
+
string = ''
|
60
|
+
escape_code_list = []
|
61
|
+
end
|
62
|
+
elsif escape_code != INACTIVE
|
63
|
+
escape_code += char
|
64
|
+
if is_complete_escape_code(escape_code)
|
65
|
+
escape_code_list << "#{ESCAPE_BYTE.chr}#{escape_code}"
|
66
|
+
escape_code = INACTIVE
|
67
|
+
end
|
68
|
+
else
|
69
|
+
string += char
|
70
|
+
end
|
71
|
+
end
|
72
|
+
return_data
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.is_complete_escape_code(escape_code)#assumes escape character is removed
|
76
|
+
return false if escape_code == '' or escape_code == nil
|
77
|
+
escape_code[-1] != escape_code[-1].dup.swapcase
|
78
|
+
end
|
79
|
+
|
36
80
|
private
|
81
|
+
def get_stripped_string
|
82
|
+
@buffer.dup.map { |line| line.join }.join("\n").strip
|
83
|
+
end
|
84
|
+
|
37
85
|
def get_buffer_contents
|
38
86
|
@buffer.dup.map do |line|
|
39
87
|
(line || []).map { |char| char || ' ' }.join
|
@@ -45,8 +93,7 @@ class BashParser
|
|
45
93
|
@escape_code += char if @escape_code != INACTIVE
|
46
94
|
@escape_code = '' if byte == ESCAPE_BYTE
|
47
95
|
|
48
|
-
|
49
|
-
if @escape_code != INACTIVE and byte_is_letter
|
96
|
+
if @escape_code != INACTIVE and BashParser.is_complete_escape_code(@escape_code)
|
50
97
|
handle_escape_code
|
51
98
|
@escape_code = INACTIVE
|
52
99
|
end
|