From 8a0155f9c840cc4ee50dad97a13337d3fe5eb1a7 Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Fri, 16 Apr 2010 09:14:48 +0800 Subject: [PATCH] Refine code. --- src/DynamicSpecialPhrase.cc | 24 ++++++++++++------------ src/SimpTradConverterTable.h | 2 +- src/update-simptrad-table.py | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/DynamicSpecialPhrase.cc b/src/DynamicSpecialPhrase.cc index 5e0380c..8d0e16d 100644 --- a/src/DynamicSpecialPhrase.cc +++ b/src/DynamicSpecialPhrase.cc @@ -12,9 +12,9 @@ std::string DynamicSpecialPhrase::text (void) { /* get the current time */ - std::time_t time; - std::time (&time); - m_time = *std::localtime (&time); + std::time_t rawtime; + std::time (&rawtime); + m_time = *std::localtime (&rawtime); std::string result; @@ -23,7 +23,7 @@ DynamicSpecialPhrase::text (void) gint s = 0; while (s != 2) { switch (s) { - case 0: + case 0: // expect "${" pnext = m_text.find ("${", pos); if (pnext == m_text.npos) { result += m_text.substr (pos); @@ -35,7 +35,7 @@ DynamicSpecialPhrase::text (void) s = 1; } break; - case 1: + case 1: // expect "}" pnext = m_text.find ("}", pos); if (pnext == m_text.npos) { result += "${"; @@ -48,7 +48,7 @@ DynamicSpecialPhrase::text (void) s = 0; } break; - default: + default: /* should not be reached */ g_assert_not_reached (); } } @@ -66,7 +66,7 @@ DynamicSpecialPhrase::dec (gint d, const gchar *fmt) inline const std::string DynamicSpecialPhrase::year_cn (gboolean yy) { - static const gchar * digits[] = { + static const gchar * const digits[] = { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" }; @@ -90,7 +90,7 @@ DynamicSpecialPhrase::year_cn (gboolean yy) inline const std::string DynamicSpecialPhrase::month_cn (void) { - static const gchar *month_num[] = { + static const gchar * const month_num[] = { "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" }; @@ -100,7 +100,7 @@ DynamicSpecialPhrase::month_cn (void) inline const std::string DynamicSpecialPhrase::weekday_cn (void) { - static const gchar *week_num[] = { + static const gchar * const week_num[] = { "日", "一", "二", "三", "四", "五", "六" }; return week_num[m_time.tm_wday]; @@ -109,7 +109,7 @@ DynamicSpecialPhrase::weekday_cn (void) inline const std::string DynamicSpecialPhrase::hour_cn (guint i) { - static const gchar *hour_num[] = { + static const gchar * const hour_num[] = { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二", "十三", "十四", @@ -134,7 +134,7 @@ DynamicSpecialPhrase::halfhour_cn (void) inline const std::string DynamicSpecialPhrase::day_cn (void) { - static const gchar *day_num[] = { + static const gchar * const day_num[] = { "", "一", "二", "三", "四", "五", "六", "七", "八", "九", "", "十","二十", "三十" @@ -146,7 +146,7 @@ DynamicSpecialPhrase::day_cn (void) inline const std::string DynamicSpecialPhrase::minsec_cn (guint i) { - static const gchar *num[] = { + static const gchar * const num[] = { "", "一", "二", "三", "四", "五", "六", "七", "八", "九", "零", "十","二十", "三十", "四十" diff --git a/src/SimpTradConverterTable.h b/src/SimpTradConverterTable.h index 84ed3fc..7aec72a 100644 --- a/src/SimpTradConverterTable.h +++ b/src/SimpTradConverterTable.h @@ -1,4 +1,4 @@ -const wchar_t *simp_to_trad[][2] = { +const wchar_t * const simp_to_trad[][2] = { { L"〇余", L"〇餘" }, { L"〇只", L"〇隻" }, { L"一个准", L"一個準" }, diff --git a/src/update-simptrad-table.py b/src/update-simptrad-table.py index d51c3e5..7a643e2 100755 --- a/src/update-simptrad-table.py +++ b/src/update-simptrad-table.py @@ -43,7 +43,7 @@ def get_records(): def main(): - print "const wchar_t *simp_to_trad[][2] = {" + print "const wchar_t * const simp_to_trad[][2] = {" maxlen, records = get_records() for s, ts in records: print ' { L"%s", L"%s" },' % (s.encode("utf8"), ts.encode("utf8")) -- 2.7.4