Refine code.
authorPeng Huang <shawn.p.huang@gmail.com>
Fri, 16 Apr 2010 01:14:48 +0000 (09:14 +0800)
committerPeng Huang <shawn.p.huang@gmail.com>
Fri, 16 Apr 2010 01:14:48 +0000 (09:14 +0800)
src/DynamicSpecialPhrase.cc
src/SimpTradConverterTable.h
src/update-simptrad-table.py

index 5e0380c..8d0e16d 100644 (file)
@@ -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[] = {
         "", "一", "二", "三", "四",
         "五", "六", "七", "八", "九",
         "零", "十","二十", "三十", "四十"
index 84ed3fc..7aec72a 100644 (file)
@@ -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"一個準" },
index d51c3e5..7a643e2 100755 (executable)
@@ -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"))