Mercurial > hg > openttd
changeset 6158:0a9ef1907f84 draft
(svn r8906) -Feature: translation dependant formatting of dates.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 26 Feb 2007 00:36:57 +0000 |
parents | e080eca511f9 |
children | 34ef0dfaddfa |
files | src/lang/english.txt src/strings.cpp |
diffstat | 2 files changed, 28 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3137,4 +3137,9 @@ STR_MEASURE_LENGTH_HEIGHTDIFF :{BLACK}Length: {NUM}{}Height difference: {NUM} m STR_MEASURE_AREA_HEIGHTDIFF :{BLACK}Area: {NUM} x {NUM}{}Height difference: {NUM} m +############ Date formatting +STR_DATE_TINY :{STRING}-{STRING}-{NUM} +STR_DATE_SHORT :{STRING} {NUM} +STR_DATE_LONG :{STRING} {STRING} {NUM} + ########
--- a/src/strings.cpp +++ b/src/strings.cpp @@ -179,9 +179,17 @@ } -// This function takes a C-string and allocates a temporary string ID. -// The duration of the bound string is valid only until the next GetString, -// so be careful. +/** + * This function takes a C-string and allocates a temporary string ID. + * The StringID of the bound string is valid until BindCString is called + * another NUM_BOUND_STRINGS times. So be careful when using it. + * + * @note formatting a DATE_TINY calls BindCString twice, thus reduces the + * amount of 'user' bound strings by 2. + * @todo rewrite the BindCString system to make the limit flexible and + * non-round-robin. For example by using smart pointers that free + * the allocated StringID when they go out-of-scope/are freed. + */ StringID BindCString(const char *str) { int idx = (++_bind_index) & (NUM_BOUND_STRINGS - 1); @@ -285,40 +293,34 @@ static char *FormatYmdString(char *buff, Date date, const char* last) { YearMonthDay ymd; - ConvertDateToYMD(date, &ymd); - buff = strecpy(buff, GetStringPtr(ymd.day + STR_01AC_1ST - 1), last); - buff = strecpy(buff, " ", last); - buff = strecpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), last); - buff = strecpy(buff, " ", last); - - return FormatNoCommaNumber(buff, ymd.year, last); + int32 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year }; + return FormatString(buff, GetStringPtr(STR_DATE_LONG), args, 0, last); } static char *FormatMonthAndYear(char *buff, Date date, const char* last) { YearMonthDay ymd; - ConvertDateToYMD(date, &ymd); - buff = strecpy(buff, GetStringPtr(STR_MONTH_JAN + ymd.month), last); - buff = strecpy(buff, " ", last); - - return FormatNoCommaNumber(buff, ymd.year, last); + int32 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year }; + return FormatString(buff, GetStringPtr(STR_DATE_SHORT), args, 0, last); } static char *FormatTinyDate(char *buff, Date date, const char* last) { YearMonthDay ymd; + ConvertDateToYMD(date, &ymd); - ConvertDateToYMD(date, &ymd); - buff += snprintf( - buff, last - buff + 1, - " %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year - ); + char day[3]; + char month[3]; + /* We want to zero-pad the days and months */ + snprintf(day, lengthof(day), "%02i", ymd.day); + snprintf(month, lengthof(month), "%02i", ymd.month + 1); - return buff; + int32 args[3] = { BindCString(day), BindCString(month), ymd.year }; + return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last); } static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact, const char* last)