Interpolator.noEscape constructor

Interpolator.noEscape(
  1. String format, [
  2. Map<String?, dynamic> defaultVal = const {}
])

All the same to the Interpolator constructor except this one crates an interpolator which does not escape the braces.

Implementation

factory Interpolator.noEscape(String format, [Map<String?, dynamic> defaultVal  = const {}]){
	//Break the string template into
	//[segment 0] { [segment 1] { [segment 2] ... { [segment n-1]
	final segments = "$format".split(_prefix);

	List<String> bodySegs = [];
	List<String> subs = [];

	//Add [segment 0] to body segments
	bodySegs.add(segments[0]);

	//Parse interpolations of [segment 1]
	for(final segPairStr in segments.sublist(1)){
		//A segPair is in the form [interpolation] } [trailing string]
		final segPair = segPairStr.split(_suffix);
		//Add the interpolation to subs
		subs.add(segPair[0]);
		//Add the trailing string to body segments
		try{
			bodySegs.add(segPair[1]);
		}on RangeError{
			//If the '}' matching the previous '{' is missing, throw an Exception
			throw FormatException("Expected '$_suffix' to match '$_prefix' at "
								  "${formatLocation(segPairStr == segments.last?
								  	'{$format{' : format, '{$segPairStr{')}");
		}
	};

	return Interpolator._(bodySegs, subs, defaultVal);
}