src/sap.ui.core/src/sap/ui/core/format/NumberFormat.js
function parseNumberAndUnit(mUnitPatterns, sValue) {
		var oBestMatch = {
			numberValue: undefined,
			cldrCode: []
		};
		if (typeof sValue !== "string") {
			return oBestMatch;
		}
		var iBestLength = Number.POSITIVE_INFINITY;
		var sUnitCode, sKey;
		for (sUnitCode in mUnitPatterns) {
			for (sKey in mUnitPatterns[sUnitCode]) {
				//use only unit patterns
				if (sKey.indexOf("unitPattern") === 0) {
					var sUnitPattern = mUnitPatterns[sUnitCode][sKey];

					// IMPORTANT:
					// To increase performance we are using native string operations instead of regex,
					// to match the patterns against the input.
					//
					// sample input: e.g. "mi 12 tsd. ms²"
					// unit pattern: e.g. "mi {0} ms²"

					// The smallest resulting number (String length) will be the best match
					var iNumberPatternIndex = sUnitPattern.indexOf("{0}");
					var bContainsExpression = iNumberPatternIndex > -1;
					if (bContainsExpression) {

						//escape regex characters to match it properly
						var sPrefix = sUnitPattern.substring(0, iNumberPatternIndex);
						var sPostfix = sUnitPattern.substring(iNumberPatternIndex + "{0}".length);

						var bMatches = sValue.startsWith(sPrefix) && sValue.endsWith(sPostfix);

						var match = bMatches && sValue.substring(sPrefix.length, sValue.length - sPostfix.length);
						if (match) {
							//get the match with the shortest result.
							// e.g. 1km -> (.+)m -> "1k" -> length 2
							// e.g. 1km -> (.+)km -> "1" -> length 1

							if (match.length < iBestLength) {
								iBestLength = match.length;
								oBestMatch.numberValue = match;
								oBestMatch.cldrCode = [sUnitCode];
							} else if (match.length === iBestLength && oBestMatch.cldrCode.indexOf(sUnitCode) === -1) {
								//ambiguous unit (en locale)
								// e.g. 100 c -> (.+) c -> duration-century
								// e.g. 100 c -> (.+) c -> volume-cup
								oBestMatch.cldrCode.push(sUnitCode);
							}
						}
					} else if (sUnitPattern === sValue) {
						oBestMatch.cldrCode = [sUnitCode];

						//for units which do not have a number representation, get the number from the pattern
						var sNumber;
						if (sKey.endsWith("-zero")) {
							sNumber = "0";
						} else if (sKey.endsWith("-one")) {
							sNumber = "1";
						} else if (sKey.endsWith("-two")) {
							sNumber = "2";
						}
						oBestMatch.numberValue = sNumber;
						return oBestMatch;
					}
				}
			}
		}

		return oBestMatch;
	}
function parseNumberAndUnit(mUnitPatterns, sValue) {
		var oBestMatch = {
			numberValue: undefined,
			cldrCode: []
		};
		if (typeof sValue !== "string") {
			return oBestMatch;
		}
		var iBestLength = Number.POSITIVE_INFINITY;
		var sUnitCode, sKey;
		for (sUnitCode in mUnitPatterns) {
			for (sKey in mUnitPatterns[sUnitCode]) {
				//use only unit patterns
				if (sKey.indexOf("unitPattern") === 0) {
					var sUnitPattern = mUnitPatterns[sUnitCode][sKey];

					// IMPORTANT:
					// To increase performance we are using native string operations instead of regex,
					// to match the patterns against the input.
					//
					// sample input: e.g. "mi 12 tsd. ms²"
					// unit pattern: e.g. "mi {0} ms²"

					// The smallest resulting number (String length) will be the best match
					var iNumberPatternIndex = sUnitPattern.indexOf("{0}");
					var bContainsExpression = iNumberPatternIndex > -1;
					if (bContainsExpression) {

						//escape regex characters to match it properly
						var sPrefix = sUnitPattern.substring(0, iNumberPatternIndex);
						var sPostfix = sUnitPattern.substring(iNumberPatternIndex + "{0}".length);

						var bMatches = sValue.startsWith(sPrefix) && sValue.endsWith(sPostfix);

						var match = bMatches && sValue.substring(sPrefix.length, sValue.length - sPostfix.length);
						if (match) {
							//get the match with the shortest result.
							// e.g. 1km -> (.+)m -> "1k" -> length 2
							// e.g. 1km -> (.+)km -> "1" -> length 1

							if (match.length < iBestLength) {
								iBestLength = match.length;
								oBestMatch.numberValue = match;
								oBestMatch.cldrCode = [sUnitCode];
							} else if (match.length === iBestLength && oBestMatch.cldrCode.indexOf(sUnitCode) === -1) {
								//ambiguous unit (en locale)
								// e.g. 100 c -> (.+) c -> duration-century
								// e.g. 100 c -> (.+) c -> volume-cup
								oBestMatch.cldrCode.push(sUnitCode);
							}
						}
					} else if (sUnitPattern === sValue) {
						oBestMatch.cldrCode = [sUnitCode];

						//for units which do not have a number representation, get the number from the pattern
						var sNumber;
						if (sKey.endsWith("-zero")) {
							sNumber = "0";
						} else if (sKey.endsWith("-one")) {
							sNumber = "1";
						} else if (sKey.endsWith("-two")) {
							sNumber = "2";
						}
						oBestMatch.numberValue = sNumber;
						return oBestMatch;
					}
				}
			}
		}

		return oBestMatch;
	}
function parseNumberAndUnit ( mUnitPatterns , sValue ) { var oBestMatch = { numberValue : undefined , cldrCode : [ ] } ; if ( typeof sValue !== "string" ) { return oBestMatch ; } var iBestLength = Number . POSITIVE_INFINITY ; var sUnitCode , sKey ; for ( sUnitCode in mUnitPatterns ) { for ( sKey in mUnitPatterns [ sUnitCode ] ) { //use only unit patterns if ( sKey . indexOf ( "unitPattern" ) === 0 ) { var sUnitPattern = mUnitPatterns [ sUnitCode ] [ sKey ] ; // IMPORTANT: // To increase performance we are using native string operations instead of regex, // to match the patterns against the input. // // sample input: e.g. "mi 12 tsd. ms²" // unit pattern: e.g. "mi {0} ms²" // The smallest resulting number (String length) will be the best match var iNumberPatternIndex = sUnitPattern . indexOf ( "{0}" ) ; var bContainsExpression = iNumberPatternIndex > - 1 ; if ( bContainsExpression ) { //escape regex characters to match it properly var sPrefix = sUnitPattern . substring ( 0 , iNumberPatternIndex ) ; var sPostfix = sUnitPattern . substring ( iNumberPatternIndex + "{0}" . length ) ; var bMatches = sValue . startsWith ( sPrefix ) && sValue . endsWith ( sPostfix ) ; var match = bMatches && sValue . substring ( sPrefix . length , sValue . length - sPostfix . length ) ; if ( match ) { //get the match with the shortest result. // e.g. 1km -> (.+)m -> "1k" -> length 2 // e.g. 1km -> (.+)km -> "1" -> length 1 if ( match . length < iBestLength ) { iBestLength = match . length ; oBestMatch . numberValue = match ; oBestMatch . cldrCode = [ sUnitCode ] ; } else if ( match . length === iBestLength && oBestMatch . cldrCode . indexOf ( sUnitCode ) === - 1 ) { //ambiguous unit (en locale) // e.g. 100 c -> (.+) c -> duration-century // e.g. 100 c -> (.+) c -> volume-cup oBestMatch . cldrCode . push ( sUnitCode ) ; } } } else if ( sUnitPattern === sValue ) { oBestMatch . cldrCode = [ sUnitCode ] ; //for units which do not have a number representation, get the number from the pattern var sNumber ; if ( sKey . endsWith ( "-zero" ) ) { sNumber = "0" ; } else if ( sKey . endsWith ( "-one" ) ) { sNumber = "1" ; } else if ( sKey . endsWith ( "-two" ) ) { sNumber = "2" ; } oBestMatch . numberValue = sNumber ; return oBestMatch ; } } } } return oBestMatch ; }
Returns the cldr code and the number value by checking each pattern and finding the best match.

1. iterate over each unit pattern, e.g. "{0}m", "{0}km"
1a. convert it to a reg exp pattern, e.g. "^(.+)m$"
1b. match it with the input "12km" and store the value "12k" and the unit value "m"
1c. do this for each pattern and update the best result if a better match is found

A better match means most of the unit value matched and the number match is shorter.
E.g. input: 12km matches for the pattern "^(.+)m$" and the resulting value is "12k"
while the pattern "^(.+)km$" results in "12".
Since pattern "^(.+)km$" returns a shorter result it is considered the better match.

Note: the cldr data is not distinct in its patterns.
E.g. "100 c" could be in "en_gb" either 100 units of "volume-cup" or "duration-century" both having the same pattern "{0} c"
Therefore best matches will be returned in an array.

@param {object} mUnitPatterns the unit patterns
@param {string} sValue The value e.g. "12 km"
@return {object} An object containing the unit codes (key: <code>[cldrCode]</code>) and the number value (key: <code>numberValue</code>).
Values are <code>undefined</code> or an empty array if not found. E.g. <code>{
numberValue: 12,
cldrCode: [length-kilometer]
}</code>
Returns the cldr code and the number value by checking each pattern and finding the best match .