src/Generic/values/NumberConverter.cpp
/**
 * Entry point for number conversion. This is not language-specific,
 * and is not overridden in language implementations.
 **/
Entry point for number conversion. This is not language-specific,
and is not overridden in language implementations.
Entry point for number conversion . This is not language - specific and is not overridden in language implementations .
int NumberConverter::convertNumberWord(const std::wstring& input_str) {
	static boost::wregex spaces_re(L"\\s+");
	std::wstring str = boost::regex_replace(input_str, spaces_re, L" ");
	if (str.find(L" ") != std::wstring::npos || str.find(L"-") != std::wstring::npos)
		return convertComplexNumberWord(str);
	size_t length = str.length();
	std::wstring new_str = L"";
	bool all_digits = true;
	for (size_t i = 0; i < length; i++) {
		if (iswdigit(str.at(i)))
			new_str += str.at(i);
		else if (str.at(i) == L',')
			continue;
		else {
			all_digits = false;
			break;
		}
	}
	if (all_digits)
		return _wtoi(new_str.c_str());
	int ret_val_from_word = convertSpelledOutNumberWord(str);
	if (ret_val_from_word != INT_MIN) { 
		return ret_val_from_word;
	}
	return 0;
}
int NumberConverter :: convertNumberWord ( const std :: wstring & input_str ) { static boost :: wregex spaces_re ( L" \\ " ) ; std :: wstring str = boost :: regex_replace ( input_str , spaces_re , L" " ) ; if ( str . find ( L" " ) != std :: wstring :: npos || str . find ( L" " ) != std :: wstring :: npos ) return convertComplexNumberWord ( str ) ; size_t length = str . length ( ) ; std :: wstring new_str = L" " ; bool all_digits = true ; for ( size_t i = 0 ; i < length ; i ++ ) { if ( iswdigit ( str . at ( i ) ) ) new_str += str . at ( i ) ; else if ( str . at ( i ) == L' ' ) continue ; else { all_digits = false ; break ; } } if ( all_digits ) return _wtoi ( new_str . c_str ( ) ) ; int ret_val_from_word = convertSpelledOutNumberWord ( str ) ; if ( ret_val_from_word != INT_MIN ) { return ret_val_from_word ; } return 0 ; }
Entry point for number conversion.
Entry point for number conversion .
// Collapse whitespace 
 // A string consisting solely of a comma
 // will let us get here, even though
 // "all_digits" should arguably not be true.
 // However, we will return 0, as we do for
 // all nonnumeric words, so that's probably
 // all right.
 // INT_MIN signals invalid value
