diff --git a/data/data.txt b/data/data.txt index 671e14a..cdaf33f 100644 --- a/data/data.txt +++ b/data/data.txt @@ -16769,6 +16769,10 @@ _punctuation_~ ~ 0.0 ㄇㄧㄥˊ-ㄊㄧㄢ MACRO@DATE_TOMORROW_MEDIUM_ROC -8 ㄇㄧㄥˊ-ㄊㄧㄢ MACRO@DATE_TOMORROW_MEDIUM_CHINESE -8 ㄇㄧㄥˊ-ㄊㄧㄢ MACRO@DATE_TOMORROW_MEDIUM_JAPANESE -8 +ㄇㄧㄥˊ-ㄊㄧㄢ MACRO@DATE_TOMORROW_WEEKDAY_SHORT -8 +ㄇㄧㄥˊ-ㄊㄧㄢ MACRO@DATE_TOMORROW_WEEKDAY -8 +ㄇㄧㄥˊ-ㄊㄧㄢ MACRO@DATE_TOMORROW2_WEEKDAY -8 +ㄇㄧㄥˊ-ㄊㄧㄢ MACRO@DATE_TOMORROW_WEEKDAY_JAPANESE -8 ㄇㄧㄥˊ-ㄊㄧㄢ-ㄉㄜ˙ 明天的 -5.34470065 ㄇㄧㄥˊ-ㄊㄧㄢ-ㄕㄤˋ-ㄨˇ-ㄅㄚ-ㄕˊ 明天上午八時 -6.69148813 ㄇㄧㄥˊ-ㄊㄧㄢ-ㄖˋ-ㄑㄧˊ 明天日期 -8 @@ -77413,6 +77417,10 @@ _punctuation_~ ~ 0.0 ㄐㄧㄣ-ㄊㄧㄢ MACRO@DATE_TODAY_MEDIUM_ROC -8 ㄐㄧㄣ-ㄊㄧㄢ MACRO@DATE_TODAY_MEDIUM_CHINESE -8 ㄐㄧㄣ-ㄊㄧㄢ MACRO@DATE_TODAY_MEDIUM_JAPANESE -8 +ㄐㄧㄣ-ㄊㄧㄢ MACRO@DATE_TODAY_WEEKDAY_SHORT -8 +ㄐㄧㄣ-ㄊㄧㄢ MACRO@DATE_TODAY_WEEKDAY -8 +ㄐㄧㄣ-ㄊㄧㄢ MACRO@DATE_TODAY2_WEEKDAY -8 +ㄐㄧㄣ-ㄊㄧㄢ MACRO@DATE_TODAY_WEEKDAY_JAPANESE -8 ㄐㄧㄣ-ㄊㄧㄢ-ㄉㄜ˙ 今天的 -4.34181496 ㄐㄧㄣ-ㄊㄧㄢ-ㄋㄥˊ 今天能 -6.82182190 ㄐㄧㄣ-ㄊㄧㄢ-ㄏㄨㄟˋ 今天會 -5.67569387 @@ -125791,6 +125799,10 @@ _punctuation_~ ~ 0.0 ㄗㄨㄛˊ-ㄊㄧㄢ MACRO@DATE_YESTERDAY_MEDIUM_ROC -8 ㄗㄨㄛˊ-ㄊㄧㄢ MACRO@DATE_YESTERDAY_MEDIUM_CHINESE -8 ㄗㄨㄛˊ-ㄊㄧㄢ MACRO@DATE_YESTERDAY_MEDIUM_JAPANESE -8 +ㄗㄨㄛˊ-ㄊㄧㄢ MACRO@DATE_YESTERDAY_WEEKDAY_SHORT -8 +ㄗㄨㄛˊ-ㄊㄧㄢ MACRO@DATE_YESTERDAY_WEEKDAY -8 +ㄗㄨㄛˊ-ㄊㄧㄢ MACRO@DATE_YESTERDAY2_WEEKDAY -8 +ㄗㄨㄛˊ-ㄊㄧㄢ MACRO@DATE_YESTERDAY_WEEKDAY_JAPANESE -8 ㄗㄨㄛˊ-ㄊㄧㄢ-ㄉㄜ˙ 昨天的 -5.38248921 ㄗㄨㄛˊ-ㄊㄧㄢ-ㄒㄧㄚˋ-ㄨˇ 昨天下午 -5.36628012 ㄗㄨㄛˊ-ㄊㄧㄢ-ㄓㄨㄥ-ㄨˇ 昨天中午 -6.20091272 diff --git a/src/InputMacro.cpp b/src/InputMacro.cpp index a04d1ef..5b48fde 100644 --- a/src/InputMacro.cpp +++ b/src/InputMacro.cpp @@ -60,6 +60,25 @@ class InputMacroYear : public InputMacro { icu::UnicodeString pattern_; }; +class InputMacroDayOfTheWeek : public InputMacro { + public: + InputMacroDayOfTheWeek(std::string macroName, std::string calendar, int offset, icu::UnicodeString pattern) + : name_(macroName), + calendarName_(calendar), + dayOffset_(offset), + pattern_(pattern) {} + std::string name() const override { return name_; } + std::string replacement() const override { + return formatWithPattern(calendarName_, /*yearOffset*/ 0, dayOffset_, pattern_); + } + + private: + std::string name_; + std::string calendarName_; + int dayOffset_; + icu::UnicodeString pattern_; +}; + class InputMacroDateTime : public InputMacro { public: InputMacroDateTime(std::string macroName, icu::DateFormat::EStyle style) @@ -297,6 +316,97 @@ class InputMacroNextYearJapanese : public InputMacroYear { : InputMacroYear("MACRO@NEXT_YEAR_JAPANESE", "japanese", 1, "Gy") {} }; +std::string convertWeekdayUnit(std::string& original) { + // s/星期/禮拜/ + std::string src = "星期"; + std::string dst = "禮拜"; + return original.replace(original.find(src), src.length(), dst); +} + +class InputMacroWeekdayTodayShort : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayTodayShort() + : InputMacroDayOfTheWeek("MACRO@DATE_TODAY_WEEKDAY_SHORT", "", 0, "E") {} +}; + +class InputMacroWeekdayToday : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayToday() + : InputMacroDayOfTheWeek("MACRO@DATE_TODAY_WEEKDAY", "", 0, "EEEE") {} +}; + +class InputMacroWeekdayToday2 : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayToday2() + : InputMacroDayOfTheWeek("MACRO@DATE_TODAY2_WEEKDAY", "", 0, "EEEE") {} + std::string replacement () const override { + std::string original(InputMacroDayOfTheWeek::replacement()); + return convertWeekdayUnit(original); + } +}; + +class InputMacroWeekdayTodayJapanese : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayTodayJapanese() + : InputMacroDayOfTheWeek("MACRO@DATE_TODAY_WEEKDAY_JAPANESE", "japanese", 0, "EEEE") {} +}; + +class InputMacroWeekdayYesterdayShort : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayYesterdayShort() + : InputMacroDayOfTheWeek("MACRO@DATE_YESTERDAY_WEEKDAY_SHORT", "", -1, "E") {} +}; + +class InputMacroWeekdayYesterday : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayYesterday() + : InputMacroDayOfTheWeek("MACRO@DATE_YESTERDAY_WEEKDAY", "", -1, "EEEE") {} +}; + +class InputMacroWeekdayYesterday2 : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayYesterday2() + : InputMacroDayOfTheWeek("MACRO@DATE_YESTERDAY2_WEEKDAY", "", -1, "EEEE") {} + std::string replacement () const override { + std::string original(InputMacroDayOfTheWeek::replacement()); + return convertWeekdayUnit(original); + } +}; + +class InputMacroWeekdayYesterdayJapanese : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayYesterdayJapanese() + : InputMacroDayOfTheWeek("MACRO@DATE_YESTERDAY_WEEKDAY_JAPANESE", "japanese", -1, "EEEE") {} +}; + +class InputMacroWeekdayTomorrowShort : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayTomorrowShort() + : InputMacroDayOfTheWeek("MACRO@DATE_TOMORROW_WEEKDAY_SHORT", "", -1, "E") {} +}; + +class InputMacroWeekdayTomorrow : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayTomorrow() + : InputMacroDayOfTheWeek("MACRO@DATE_TOMORROW_WEEKDAY", "", -1, "EEEE") {} +}; + +class InputMacroWeekdayTomorrow2 : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayTomorrow2() + : InputMacroDayOfTheWeek("MACRO@DATE_TOMORROW2_WEEKDAY", "", -1, "EEEE") {} + std::string replacement () const override { + std::string original(InputMacroDayOfTheWeek::replacement()); + return convertWeekdayUnit(original); + } +}; + +class InputMacroWeekdayTomorrowJapanese : public InputMacroDayOfTheWeek { + public: + InputMacroWeekdayTomorrowJapanese() + : InputMacroDayOfTheWeek("MACRO@DATE_TOMORROW_WEEKDAY_JAPANESE", "japanese", -1, "EEEE") {} +}; + class InputMacroDateTimeNowShort : public InputMacroDateTime { public: InputMacroDateTimeNowShort() @@ -387,6 +497,18 @@ InputMacroController::InputMacroController() { AddMacro(macros_, std::make_unique()); AddMacro(macros_, std::make_unique()); AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); + AddMacro(macros_, std::make_unique()); AddMacro(macros_, std::make_unique()); AddMacro(macros_, std::make_unique()); AddMacro(macros_, std::make_unique());