From 9e663cba1ee6d6513803c58d5fb19704e254efbd Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 31 Mar 2005 02:26:37 +0000 Subject: [PATCH] add AddNumberSuffix --- stepmania/src/RageUtil.cpp | 18 ++++++++++++++++++ stepmania/src/RageUtil.h | 1 + 2 files changed, 19 insertions(+) diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index b820652907..3ae32fefcb 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -166,6 +166,24 @@ CString Commify( int iNum ) return sReturn; } +CString AddNumberSuffix( int i ) +{ + CString sSuffix; + switch( i%10 ) + { + case 1: sSuffix = "st"; break; + case 2: sSuffix = "nd"; break; + case 3: sSuffix = "rd"; break; + default: sSuffix = "th"; break; + } + + // "11th", "113th", etc. + if( ((i%100) / 10) == 1 ) + sSuffix = "th"; + + return ssprintf("%i", i) + sSuffix; +} + struct tm GetLocalTime() { const time_t t = time(NULL); diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 3ed850d795..890eee8130 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -198,6 +198,7 @@ CString SecondsToMMSSMsMsMs( float fSecs ); CString PrettyPercent( float fNumerator, float fDenominator ); inline CString PrettyPercent( int fNumerator, int fDenominator ) { return PrettyPercent( float(fNumerator), float(fDenominator) ); } CString Commify( int iNum ); +CString AddNumberSuffix( int i ); struct tm GetLocalTime();