Module: SchemeStrings

Includes:
SchemeStringsHelper
Included in:
Tokenizer
Defined in:
lib/lisp/interpreter/core/strings.rb

Overview

Scheme numbers module

Instance Method Summary collapse

Methods included from SchemeStringsHelper

#arg_function_validator, #build_as_string_helper, #build_character, #build_next_value_as_string, #find_delimeter, #remove_carriage, #string_join_helper, #strjoin_validate, #substring_builder, #substring_validator

Instance Method Details

#strcontains(other) ⇒ Object



96
97
98
99
100
# File 'lib/lisp/interpreter/core/strings.rb', line 96

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



91
92
93
94
# File 'lib/lisp/interpreter/core/strings.rb', line 91

def strdowncase(other)
  arg_function_validator other
  other[0].downcase
end

#string?(other) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
# File 'lib/lisp/interpreter/core/strings.rb', line 75

def string?(other)
  raise arg_err_build 1, other.size if other.size != 1
  result = check_for_string other[0].to_s
  result ? '#t' : '#f'
end

#strjoin(other) ⇒ Object



135
136
137
138
139
# File 'lib/lisp/interpreter/core/strings.rb', line 135

def strjoin(other)
  strjoin_validate other
  arg_function_validator [other[1]] if other.size == 2
  string_join_helper other[0], other[1]
end

#strlen(other) ⇒ Object



81
82
83
84
# File 'lib/lisp/interpreter/core/strings.rb', line 81

def strlen(other)
  arg_function_validator other
  other[0][1..-2].length
end

#strlist(other) ⇒ Object



109
110
111
112
113
# File 'lib/lisp/interpreter/core/strings.rb', line 109

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



121
122
123
124
125
126
# File 'lib/lisp/interpreter/core/strings.rb', line 121

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



115
116
117
118
119
# File 'lib/lisp/interpreter/core/strings.rb', line 115

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



102
103
104
105
106
107
# File 'lib/lisp/interpreter/core/strings.rb', line 102

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



128
129
130
131
132
133
# File 'lib/lisp/interpreter/core/strings.rb', line 128

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



86
87
88
89
# File 'lib/lisp/interpreter/core/strings.rb', line 86

def strupcase(other)
  arg_function_validator other
  other[0].upcase
end

#substring(other) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/lisp/interpreter/core/strings.rb', line 67

def substring(other)
  raise arg_err_build '[2, 3]', other.size unless other.size.between? 2, 3
  str, from, to = other
  arg_function_validator [str]
  substring_validator from, to
  substring_builder str, from.to_num, to.to_num
end