10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/cloudrail_si/servicecode/commands/string/Substr.rb', line 10
def execute(environment, parameters)
Helper.assert((parameters.length === 3 ||
parameters.length === 4) &&
Helper.is_var_address(parameters[0]))
result_var = parameters[0]
source_string = Helper.resolve(environment, parameters[1])
Helper.assert(Helper.is_string(source_string))
start_idx = Helper.resolve(environment, parameters[2])
Helper.assert(Helper.is_number(start_idx))
length = source_string.length - start_idx
if (parameters.length === 4)
length = Helper.resolve(environment, parameters[3])
Helper.assert(Helper.is_number(length))
Helper.assert(length + start_idx <= source_string.length)
end
res = source_string[start_idx..start_idx + length - 1]
environment.set_variable(result_var, res)
end
|