function trimWhitespaceInRange(rng, text, mask) {
						mask = mask || (WHITESPACE_REMOVE_FROM_START | WHITESPACE_REMOVE_FROM_END);
						text = rng.substring(text);
						var m;
						if ((mask & WHITESPACE_REMOVE_FROM_START) && (m = text.match(reSpaceStart))) {
							rng.start += m[0].length;
						}

						if ((mask & WHITESPACE_REMOVE_FROM_END) && (m = text.match(reSpaceEnd))) {
							rng.end -= m[0].length;
						}

						// in case given range is just a whatespace
						if (rng.end < rng.start) {
							rng.end = rng.start;
						}

						return rng;
					}
Modifies given range to remove whitespace from beginning
and/or from the end
@param  {Range} rng Range to modify
@param  {String} text  Text that range belongs to
@param  {Number} mask  Mask indicating from which end 
whitespace should be removed
@return {Range}