Skip to content

Commit

Permalink
[values][builtins] Add immutable parameter to string building funct…
Browse files Browse the repository at this point in the history
…ions [#68]
  • Loading branch information
cipriancraciun committed Jun 9, 2018
1 parent 7e4ab14 commit 00a23c3
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 110 deletions.
28 changes: 14 additions & 14 deletions sources/builtins_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,13 @@ pub fn bytes_iterate_n (evaluator : &mut EvaluatorContext, callable : &Value, by

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn strings_map_1 (evaluator : &mut EvaluatorContext, callable : &Value, string : &Value) -> (Outcome<Value>) {
pub fn strings_map_1 (evaluator : &mut EvaluatorContext, callable : &Value, string : &Value, immutable : Option<bool>) -> (Outcome<Value>) {
if try! (is_string_empty (string)) {
succeed! (string_empty ());
succeed! (string_empty (immutable));
}
let iterator = try! (StringIterator::new (string));
let outputs = try! (iterators_map_1 (evaluator, callable, iterator));
return string_collect_values (outputs);
return string_collect_values (outputs, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
Expand All @@ -731,14 +731,14 @@ pub fn strings_iterate_1 (evaluator : &mut EvaluatorContext, callable : &Value,

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn strings_map_2 (evaluator : &mut EvaluatorContext, callable : &Value, string_1 : &Value, string_2 : &Value) -> (Outcome<Value>) {
pub fn strings_map_2 (evaluator : &mut EvaluatorContext, callable : &Value, string_1 : &Value, string_2 : &Value, immutable : Option<bool>) -> (Outcome<Value>) {
if try! (is_string_empty_all_2 (string_1, string_2)) {
succeed! (string_empty ());
succeed! (string_empty (immutable));
}
let iterator_1 = try! (StringIterator::new (string_1));
let iterator_2 = try! (StringIterator::new (string_2));
let outputs = try! (iterators_map_2 (evaluator, callable, iterator_1, iterator_2));
return string_collect_values (outputs);
return string_collect_values (outputs, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
Expand All @@ -756,15 +756,15 @@ pub fn strings_iterate_2 (evaluator : &mut EvaluatorContext, callable : &Value,

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn strings_map_3 (evaluator : &mut EvaluatorContext, callable : &Value, string_1 : &Value, string_2 : &Value, string_3 : &Value) -> (Outcome<Value>) {
pub fn strings_map_3 (evaluator : &mut EvaluatorContext, callable : &Value, string_1 : &Value, string_2 : &Value, string_3 : &Value, immutable : Option<bool>) -> (Outcome<Value>) {
if try! (is_string_empty_all_3 (string_1, string_2, string_3)) {
succeed! (string_empty ());
succeed! (string_empty (immutable));
}
let iterator_1 = try! (StringIterator::new (string_1));
let iterator_2 = try! (StringIterator::new (string_2));
let iterator_3 = try! (StringIterator::new (string_3));
let outputs = try! (iterators_map_3 (evaluator, callable, iterator_1, iterator_2, iterator_3));
return string_collect_values (outputs);
return string_collect_values (outputs, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
Expand All @@ -783,16 +783,16 @@ pub fn strings_iterate_3 (evaluator : &mut EvaluatorContext, callable : &Value,

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn strings_map_4 (evaluator : &mut EvaluatorContext, callable : &Value, string_1 : &Value, string_2 : &Value, string_3 : &Value, string_4 : &Value) -> (Outcome<Value>) {
pub fn strings_map_4 (evaluator : &mut EvaluatorContext, callable : &Value, string_1 : &Value, string_2 : &Value, string_3 : &Value, string_4 : &Value, immutable : Option<bool>) -> (Outcome<Value>) {
if try! (is_string_empty_all_4 (string_1, string_2, string_3, string_4)) {
succeed! (string_empty ());
succeed! (string_empty (immutable));
}
let iterator_1 = try! (StringIterator::new (string_1));
let iterator_2 = try! (StringIterator::new (string_2));
let iterator_3 = try! (StringIterator::new (string_3));
let iterator_4 = try! (StringIterator::new (string_4));
let outputs = try! (iterators_map_4 (evaluator, callable, iterator_1, iterator_2, iterator_3, iterator_4));
return string_collect_values (outputs);
return string_collect_values (outputs, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
Expand All @@ -812,13 +812,13 @@ pub fn strings_iterate_4 (evaluator : &mut EvaluatorContext, callable : &Value,

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn strings_map_n (evaluator : &mut EvaluatorContext, callable : &Value, strings : &[impl StdAsRef<Value>]) -> (Outcome<Value>) {
pub fn strings_map_n (evaluator : &mut EvaluatorContext, callable : &Value, strings : &[impl StdAsRef<Value>], immutable : Option<bool>) -> (Outcome<Value>) {
if strings.is_empty () {
fail! (0x75dac57b);
}
let iterators = try! (StringIterators::new (strings));
let outputs = try! (iterators_map_n (evaluator, callable, iterators));
return string_collect_values (outputs);
return string_collect_values (outputs, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
Expand Down
44 changes: 22 additions & 22 deletions sources/builtins_ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,28 +398,28 @@ pub fn port_input_bytes_read_extend (port : &Value, bytes : &Value, count : Opti

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect (port : &Value, count : Option<&Value>, full : Option<bool>) -> (Outcome<Value>) {
pub fn port_input_string_read_collect (port : &Value, count : Option<&Value>, full : Option<bool>, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let (port, count, full, buffer_size) = try! (port_input_coerce_arguments (port, count, full, false));
let mut buffer = StdString::with_capacity (buffer_size);
if let Some (_) = try! (port.char_read_string (&mut buffer, count, full)) {
succeed! (string_new (buffer) .into ());
succeed! (string_new (buffer, immutable) .into ());
} else {
succeed! (PORT_EOF.into ());
}
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect_fold (port : &Value, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext) -> (Outcome<Value>) {
pub fn port_input_string_read_collect_fold (port : &Value, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let (port, count, full, buffer_size) = try! (port_input_coerce_arguments (port, count, full, false));
let mut accumulator = accumulator.clone ();
loop {
TODO! ("use `Rc` of buffer and try to re-use it if the callable doesn't uses it anymore");
let mut buffer = StdString::with_capacity (buffer_size);
if let Some (_) = try! (port.char_read_string (&mut buffer, count, full)) {
let value = string_new (buffer) .into ();
let value = string_new (buffer, immutable) .into ();
accumulator = try! (evaluator.evaluate_procedure_call_2 (callable, &value, &accumulator));
} else {
succeed! (accumulator);
Expand Down Expand Up @@ -620,32 +620,32 @@ fn port_input_bytes_read_extend_until_0 (port : &Value, bytes : &Value, delimite

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect_until (port : &Value, delimiter : Option<&Value>, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>) -> (Outcome<Value>) {
pub fn port_input_string_read_collect_until (port : &Value, delimiter : Option<&Value>, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let delimiter = if let Some (delimiter) = delimiter { try_as_character_ref! (delimiter) .value () } else { DEFAULT_PORT_OUTPUT_NEWLINE_SEPARATOR };
return port_input_string_read_collect_until_0 (port, delimiter, include_delimiter, count, full);
return port_input_string_read_collect_until_0 (port, delimiter, include_delimiter, count, full, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect_line (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>) -> (Outcome<Value>) {
pub fn port_input_string_read_collect_line (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let delimiter = DEFAULT_PORT_OUTPUT_NEWLINE_SEPARATOR;
return port_input_string_read_collect_until_0 (port, delimiter, include_delimiter, count, full);
return port_input_string_read_collect_until_0 (port, delimiter, include_delimiter, count, full, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect_zero (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>) -> (Outcome<Value>) {
pub fn port_input_string_read_collect_zero (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let delimiter = DEFAULT_PORT_OUTPUT_ZERO_SEPARATOR;
return port_input_string_read_collect_until_0 (port, delimiter, include_delimiter, count, full);
return port_input_string_read_collect_until_0 (port, delimiter, include_delimiter, count, full, immutable);
}


#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
fn port_input_string_read_collect_until_0 (port : &Value, delimiter : char, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>) -> (Outcome<Value>) {
fn port_input_string_read_collect_until_0 (port : &Value, delimiter : char, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let (port, count, full, buffer_size) = try! (port_input_coerce_arguments (port, count, full, true));
let include_delimiter = include_delimiter.unwrap_or (false);
Expand All @@ -660,7 +660,7 @@ fn port_input_string_read_collect_until_0 (port : &Value, delimiter : char, incl
fail_panic! (0xec6380c4, github_issue_new);
}
}
succeed! (string_new (buffer) .into ());
succeed! (string_new (buffer, immutable) .into ());
} else {
succeed! (PORT_EOF.into ());
}
Expand All @@ -671,32 +671,32 @@ fn port_input_string_read_collect_until_0 (port : &Value, delimiter : char, incl

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect_until_fold (port : &Value, delimiter : Option<&Value>, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext) -> (Outcome<Value>) {
pub fn port_input_string_read_collect_until_fold (port : &Value, delimiter : Option<&Value>, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let delimiter = if let Some (delimiter) = delimiter { try_as_character_ref! (delimiter) .value () } else { DEFAULT_PORT_OUTPUT_NEWLINE_SEPARATOR };
return port_input_string_read_collect_until_fold_0 (port, delimiter, include_delimiter, count, full, callable, accumulator, evaluator);
return port_input_string_read_collect_until_fold_0 (port, delimiter, include_delimiter, count, full, callable, accumulator, evaluator, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect_line_fold (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext) -> (Outcome<Value>) {
pub fn port_input_string_read_collect_line_fold (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let delimiter = DEFAULT_PORT_OUTPUT_NEWLINE_SEPARATOR;
return port_input_string_read_collect_until_fold_0 (port, delimiter, include_delimiter, count, full, callable, accumulator, evaluator);
return port_input_string_read_collect_until_fold_0 (port, delimiter, include_delimiter, count, full, callable, accumulator, evaluator, immutable);
}

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_input_string_read_collect_zero_fold (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext) -> (Outcome<Value>) {
pub fn port_input_string_read_collect_zero_fold (port : &Value, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let delimiter = DEFAULT_PORT_OUTPUT_ZERO_SEPARATOR;
return port_input_string_read_collect_until_fold_0 (port, delimiter, include_delimiter, count, full, callable, accumulator, evaluator);
return port_input_string_read_collect_until_fold_0 (port, delimiter, include_delimiter, count, full, callable, accumulator, evaluator, immutable);
}


#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
fn port_input_string_read_collect_until_fold_0 (port : &Value, delimiter : char, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext) -> (Outcome<Value>) {
fn port_input_string_read_collect_until_fold_0 (port : &Value, delimiter : char, include_delimiter : Option<bool>, count : Option<&Value>, full : Option<bool>, callable : &Value, accumulator : &Value, evaluator : &mut EvaluatorContext, immutable : Option<bool>) -> (Outcome<Value>) {
//! NOTE: For `count` and `full` handling see the documentation for [`port_input_coerce_arguments`]!
let (port, count, full, buffer_size) = try! (port_input_coerce_arguments (port, count, full, true));
let include_delimiter = include_delimiter.unwrap_or (false);
Expand All @@ -714,7 +714,7 @@ fn port_input_string_read_collect_until_fold_0 (port : &Value, delimiter : char,
fail_panic! (0x946e6d5d, github_issue_new);
}
}
let value = string_new (buffer) .into ();
let value = string_new (buffer, immutable) .into ();
accumulator = try! (evaluator.evaluate_procedure_call_2 (callable, &value, &accumulator));
} else {
succeed! (accumulator);
Expand Down Expand Up @@ -1045,15 +1045,15 @@ pub fn port_bytes_writer_finalize (port : &Value, immutable : Option<bool>) -> (

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn port_string_writer_finalize (port : &Value) -> (Outcome<Value>) {
pub fn port_string_writer_finalize (port : &Value, immutable : Option<bool>) -> (Outcome<Value>) {
let port = try_as_port_ref! (port);
let mut port = try! (port.internals_ref_mut ());
let port = port.backend_ref_mut ();
match *port {
PortBackend::BytesWriter (ref mut backend) => {
let buffer = try! (backend.finalize ());
if let Ok (string) = StdString::from_utf8 (buffer) {
succeed! (string_new (string) .into ());
succeed! (string_new (string, immutable) .into ());
} else {
fail! (0xfa7d2f1a);
}
Expand Down
8 changes: 4 additions & 4 deletions sources/builtins_regularex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ pub fn string_regex_matches (pattern : &Value, string : &Value) -> (Outcome<bool

#[ cfg ( feature = "vonuvoli_values_string" ) ]
#[ cfg_attr ( feature = "vonuvoli_inline", inline ) ]
pub fn string_regex_match_extract_first (pattern : &Value, string : &Value) -> (Outcome<Value>) {
pub fn string_regex_match_extract_first (pattern : &Value, string : &Value, immutable : Option<bool>) -> (Outcome<Value>) {
let pattern = try_as_string_regex_ref! (pattern);
let pattern = pattern.regex_ref ();
let string = try_as_string_ref! (string);
let string = string.string_as_str ();
if let Some (matched) = pattern.find (string) {
let extract = string_clone_str (matched.as_str ());
let extract = string_clone_str (matched.as_str (), immutable);
succeed! (extract.into ());
} else {
succeed! (FALSE_VALUE);
Expand All @@ -107,7 +107,7 @@ pub fn string_regex_match_extract_all (pattern : &Value, string : &Value, return
let string = string.string_as_str ();
let mut extracts = StdVec::new ();
for matched in pattern.find_iter (string) {
let extract = string_clone_str (matched.as_str ());
let extract = string_clone_str (matched.as_str (), immutable);
extracts.push (extract);
}
return build_list_or_array_or_false_if_empty (extracts, return_array, immutable);
Expand Down Expand Up @@ -214,7 +214,7 @@ fn string_regex_match_captures_extract_0 (pattern : &ext::regex::Regex, captures
let mut extracts = StdVec::new ();
for (index, (name, matched)) in pattern.capture_names () .zip (captures.iter ()) .enumerate () {
let extract = if let Some (matched) = matched {
string_clone_str (matched.as_str ()) .into ()
string_clone_str (matched.as_str (), immutable) .into ()
} else {
FALSE_VALUE
};
Expand Down
2 changes: 1 addition & 1 deletion sources/builtins_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub fn serde_ast_to_value (value : ValueSerde) -> (Outcome<Value>) {

#[ cfg ( feature = "vonuvoli_values_string" ) ]
ValueSerde::String (value) =>
succeed! (string_new (value) .into ()),
succeed! (string_new (value, None) .into ()),
#[ cfg ( feature = "vonuvoli_values_bytes" ) ]
ValueSerde::Bytes (value) =>
succeed! (bytes_new (value, None) .into ()),
Expand Down
Loading

0 comments on commit 00a23c3

Please sign in to comment.