w/resources/src/mediawiki/mediawiki.String.js
/**
	 * Utility function to trim down a string, based on codePointLimit
	 * and given a safe start position. It supports insertion anywhere
	 * in the string, so "foo" to "fobaro" if limit is 4 will result in
	 * "fobo", not "foba". Basically emulating the native maxlength by
	 * reconstructing where the insertion occurred.
	 *
	 * @param {string} safeVal Known value that was previously returned by this
	 * function, if none, pass empty string.
	 * @param {string} newVal New value that may have to be trimmed down.
	 * @param {number} codePointLimit Number of characters the value may be in size.
	 * @param {Function} [filterFn] Function to call on the string before assessing the length.
	 * @return {Object}
	 * @return {string} return.newVal
	 * @return {boolean} return.trimmed
	 */
Utility function to trim down a string, based on codePointLimit
and given a safe start position.

@param {string} safeVal Known value that was previously returned by this
function, if none, pass empty string.
@param {string} newVal New value that may have to be trimmed down.
@param {number} codePointLimit Number of characters the value may be in size.
@param {Function} [filterFn] Function to call on the string before assessing the length.
Utility function to trim down a string based on codePointLimit and given a safe start position . @param { string } safeVal Known value that was previously returned by this function if none pass empty string . @param { string } newVal New value that may have to be trimmed down . @param { number } codePointLimit Number of characters the value may be in size . @param { Function } [ filterFn ] Function to call on the string before assessing the length .
function trimCodePointLength( safeVal, newVal, codePointLimit, filterFn ) {
		var lengthFn;
		if ( filterFn ) {
			lengthFn = function ( val ) {
				return codePointLength( filterFn( val ) );
			};
		} else {
			lengthFn = codePointLength;
		}
		return trimLength( safeVal, newVal, codePointLimit, lengthFn );
	}
function trimCodePointLength ( safeVal , newVal , codePointLimit , filterFn ) { var lengthFn ; if ( filterFn ) { lengthFn = function ( val ) { return codePointLength ( filterFn ( val ) ) ; } ; } else { lengthFn = codePointLength ; } return trimLength ( safeVal , newVal , codePointLimit , lengthFn ) ; }
Utility function to trim down a string, based on codePointLimit
 and given a safe start position.
Utility function to trim down a string based on codePointLimit and given a safe start position .