Module: SchemeStrings
Overview
Instance Method Summary
collapse
#arg_function_validator, #build_as_string_helper, #build_character, #build_next_value_as_string, #find_delimeter, #remove_carriage, #string_join_helper, #substring_builder
Instance Method Details
#strcontains(other) ⇒ Object
86
87
88
89
90
|
# File 'lib/lisp/interpreter/strings.rb', line 86
def strcontains(other)
arg_function_validator other, 2
result = other[0][1..-2].include? other[1][1..-2]
result ? '#t' : '#f'
end
|
#strdowncase(other) ⇒ Object
81
82
83
84
|
# File 'lib/lisp/interpreter/strings.rb', line 81
def strdowncase(other)
arg_function_validator other
other[0].downcase
end
|
#string?(other) ⇒ Boolean
65
66
67
68
69
|
# File 'lib/lisp/interpreter/strings.rb', line 65
def string?(other)
raise 'Incorrect number of arguments' if other.size != 1
result = check_for_string other[0].to_s
result ? '#t' : '#f'
end
|
#strjoin(other) ⇒ Object
125
126
127
128
129
130
|
# File 'lib/lisp/interpreter/strings.rb', line 125
def strjoin(other)
raise 'Incorrect number of arguments' unless other.size.between? 1, 2
raise 'Invalid data type' unless other[0].to_s.list?
arg_function_validator [other[1]] if other.size == 2
string_join_helper other[0], other[1]
end
|
#strlen(other) ⇒ Object
71
72
73
74
|
# File 'lib/lisp/interpreter/strings.rb', line 71
def strlen(other)
arg_function_validator other
other[0][1..-2].length
end
|
#strlist(other) ⇒ Object
99
100
101
102
103
|
# File 'lib/lisp/interpreter/strings.rb', line 99
def strlist(other)
arg_function_validator other
result = other[0][1..-2].chars.map { |c| build_character c }
build_list result
end
|
#strprefix(other) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/lisp/interpreter/strings.rb', line 111
def strprefix(other)
arg_function_validator other, 2
str, to_check = other.map { |t| t[1..-2] }
result = str.start_with? to_check
result ? '#t' : '#f'
end
|
#strreplace(other) ⇒ Object
105
106
107
108
109
|
# File 'lib/lisp/interpreter/strings.rb', line 105
def strreplace(other)
arg_function_validator other, 3
str, to_replace, replace_with = other.map { |t| t[1..-2] }
'"' + (str.gsub to_replace, replace_with) + '"'
end
|
#strsplit(other) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/lisp/interpreter/strings.rb', line 92
def strsplit(other)
arg_function_validator other
str = remove_carriage other[0]
result = str.split(' ').map { |s| '"' + s + '"' }
build_list result
end
|
#strsufix(other) ⇒ Object
118
119
120
121
122
123
|
# File 'lib/lisp/interpreter/strings.rb', line 118
def strsufix(other)
arg_function_validator other, 2
str, to_check = other.map { |t| t[1..-2] }
result = str.end_with? to_check
result ? '#t' : '#f'
end
|
#strupcase(other) ⇒ Object
76
77
78
79
|
# File 'lib/lisp/interpreter/strings.rb', line 76
def strupcase(other)
arg_function_validator other
other[0].upcase
end
|
#substring(other) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/lisp/interpreter/strings.rb', line 56
def substring(other)
raise 'Incorrect number of arguments' unless other.size.between? 2, 3
str, from, to = other
arg_function_validator [str]
valid = (check_for_number from) && (to.nil? || (check_for_number to))
raise 'Incorrect parameter type' unless valid
substring_builder str, from.to_num, to.to_num
end
|