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_next_value_as_string, #find_delimeter, #remove_carriage, #string_join_helper, #strjoin_validate, #substring_builder, #substring_validator

Instance Method Details

#strcontains(other) ⇒ Object



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

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



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

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

#string?(other) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/lisp/interpreter/core/strings.rb', line 71

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

#strjoin(other) ⇒ Object



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

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



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

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

#strlist(other) ⇒ Object



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

def strlist(other)
  arg_function_validator other
  result = other[0][1..-2].chars.map(&:to_char)
  build_list result
end

#strprefix(other) ⇒ Object



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

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



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

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



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

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



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

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



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

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

#substring(other) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/lisp/interpreter/core/strings.rb', line 63

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