From: <vo...@us...> - 2013-04-28 14:36:17
|
Revision: 3794 http://sourceforge.net/p/moneymanagerex/code/3794 Author: vomikan Date: 2013-04-28 14:36:14 +0000 (Sun, 28 Apr 2013) Log Message: ----------- no decimal char if no cents used Modified Paths: -------------- trunk/mmex/src/util.cpp Modified: trunk/mmex/src/util.cpp =================================================================== --- trunk/mmex/src/util.cpp 2013-04-28 11:18:29 UTC (rev 3793) +++ trunk/mmex/src/util.cpp 2013-04-28 14:36:14 UTC (rev 3794) @@ -149,9 +149,13 @@ wxString format_cents(const mmex::CurrencyFormatter &f, int cents) { - wxString s = wxString() << cents << "000000"; - s.Truncate(log10(f.getScale())); - s.Prepend(f.getDecimalPoint()); + wxString s =""; + if (f.getScale() >= 10) + { + s << cents << "000000"; + s.Truncate(log10(f.getScale())); + s.Prepend(f.getDecimalPoint()); + } return s; } //---------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vo...@us...> - 2013-05-03 06:52:12
|
Revision: 3823 http://sourceforge.net/p/moneymanagerex/code/3823 Author: vomikan Date: 2013-05-03 06:52:06 +0000 (Fri, 03 May 2013) Log Message: ----------- cleanup and bug fix Modified Paths: -------------- trunk/mmex/src/util.cpp Modified: trunk/mmex/src/util.cpp =================================================================== --- trunk/mmex/src/util.cpp 2013-05-03 05:48:53 UTC (rev 3822) +++ trunk/mmex/src/util.cpp 2013-05-03 06:52:06 UTC (rev 3823) @@ -75,113 +75,6 @@ } //---------------------------------------------------------------------------- -#if 0 -double mmRound(double x) -{ - x += (x < 0 ? -0.5 : 0.5); - - double n = 0; - modf(x, &n); - - return n; -} -//---------------------------------------------------------------------------- - -double mmMoneyInt(double x, int scale) -{ - double n = 0; - modf(x/scale, &n); - return n; -} -//---------------------------------------------------------------------------- - -int mmCents(double x, int scale) -{ - x += (x < 0 ? -0.5 : 0.5); - - double dummy = 0; - double fract = modf(x/scale, &dummy); - - return static_cast<int>(fract*scale); -} -//---------------------------------------------------------------------------- - -wchar_t get_group_separator(wxChar sep) -{ - wxString s(sep); - return *s.wc_str(*wxConvCurrent); -} -//---------------------------------------------------------------------------- - -/* - Formats groups of 3 digits separated by group_separator. - - Empty separator means zero will be inserted. - Thus, if separator is not a printable char, it ignores. - The same for decimal point char. -*/ -wxString format_groups(const mmex::CurrencyFormatter &fmt, double x, size_t grp_sz) -{ - wxString val; - val.Printf("%.0f", x); - - wxChar grp_sep = fmt.getGroupSeparator(); - - if (wxIsprint(grp_sep) && val.length() > grp_sz) - { - wchar_t sep = get_group_separator(grp_sep); - - std::wstring s; - s.reserve(val.length() + val.length()/grp_sz); - s.assign(val.wc_str(*wxConvCurrent), val.length()); - - for (size_t i = 0, j = i + grp_sz*(i+1); j < s.length(); ++i, j = i + grp_sz*(i+1)) - { - std::wstring::iterator it = s.begin(); - std::advance(it, s.length() - j); - s.insert(it, sep); - } - - val = wxString(s.data(), *wxConvCurrent, s.length()); - } - - return val; -} -//---------------------------------------------------------------------------- - -wxString format_cents(const mmex::CurrencyFormatter &f, int cents) -{ - wxString s =""; - if (f.getScale() >= 10) - { - s << cents << "000000"; - s.Truncate(f.getDec()); - s.Prepend(f.getDecimalPoint()); - } - return s; -} -//---------------------------------------------------------------------------- - -void DoubleToCurrency(const mmex::CurrencyFormatter &fmt, double val, wxString& rdata, bool for_edit) -{ - int scale = fmt.getScale(); - double abs_val = fabs(mmRound(val*scale)); - - rdata = format_groups(fmt, mmMoneyInt(abs_val, scale), 3); - rdata += format_cents(fmt, mmCents(abs_val, scale)); - - if (val < 0) - rdata.Prepend("-"); // "minus" sign - - if (!for_edit) - rdata += fmt.getSuffix(); - - if (!for_edit && !fmt.getPrefix().IsEmpty()) - rdata.Prepend(fmt.getPrefix().Append(" ")); -} -#endif // 0 -//---------------------------------------------------------------------------- - } // namespace //---------------------------------------------------------------------------- @@ -243,6 +136,8 @@ void mmex::formatDoubleToCurrencyEdit(double val, wxString& rdata) { rdata = wxNumberFormatter::ToString(val, 0x02); // Style_WithThousandsSep + //TODO: Remove it with new wx release + rdata.Replace("-,", "-"); } void mmex::formatDoubleToCurrency(double val, wxString& rdata) @@ -251,6 +146,8 @@ rdata = wxNumberFormatter::ToString(val, 0x02); // Style_WithThousandsSep rdata.Prepend(fmt.getPrefix()); rdata.Append(fmt.getSuffix()); + //TODO: Remove it with new wx release + rdata.Replace("-,", "-"); } bool mmex::formatCurrencyToDouble(const wxString& str, double& val) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vo...@us...> - 2013-05-03 09:03:58
|
Revision: 3824 http://sourceforge.net/p/moneymanagerex/code/3824 Author: vomikan Date: 2013-05-03 09:03:44 +0000 (Fri, 03 May 2013) Log Message: ----------- update Modified Paths: -------------- trunk/mmex/src/util.cpp Modified: trunk/mmex/src/util.cpp =================================================================== --- trunk/mmex/src/util.cpp 2013-05-03 06:52:06 UTC (rev 3823) +++ trunk/mmex/src/util.cpp 2013-05-03 09:03:44 UTC (rev 3824) @@ -644,19 +644,19 @@ int i=0; //Single quotes will be used instead double quotes //Replace all single quotes first - line.Replace("'", "SingleQuotesReplacer12345"); + line.Replace("'", "\6"); //Replace double quotes that used twice to replacer - line.Replace("\"\"\""+delimit+"\"\"\"", "DoubleQuotesReplacer12345\""+delimit+"\"DoubleQuotesReplacer12345"); - line.Replace("\"\"\""+delimit, "DoubleQuotesReplacer12345\""+delimit); - line.Replace(delimit+"\"\"\"", delimit+"\"DoubleQuotesReplacer12345"); - line.Replace("\"\""+delimit, "DoubleQuotesReplacer12345"+delimit); - line.Replace(delimit+"\"\"", delimit+"DoubleQuotesReplacer12345"); + line.Replace("\"\"\""+delimit+"\"\"\"", "\5\""+delimit+"\"\5"); + line.Replace("\"\"\""+delimit, "\5\""+delimit); + line.Replace(delimit+"\"\"\"", delimit+"\"\5"); + line.Replace("\"\""+delimit, "\5"+delimit); + line.Replace(delimit+"\"\"", delimit+"\5"); //replace delimiter to TAB and double quotes to single quotes line.Replace("\""+delimit+"\"", "'\t'"); line.Replace("\""+delimit, "'\t"); line.Replace(delimit+"\"", "\t'"); - line.Replace("\"\"", "DoubleQuotesReplacer12345"); + line.Replace("\"\"", "\5"); line.Replace("\"", "'"); wxString temp_line = wxEmptyString; @@ -672,8 +672,8 @@ i++; }; //Replace back all replacers to the original value - temp_line.Replace("DoubleQuotesReplacer12345", "\""); - temp_line.Replace("SingleQuotesReplacer12345", "'"); + temp_line.Replace("\5", "\""); + temp_line.Replace("\6", "'"); line = temp_line; return line; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vo...@us...> - 2013-05-05 12:46:28
|
Revision: 3853 http://sourceforge.net/p/moneymanagerex/code/3853 Author: vomikan Date: 2013-05-05 12:46:25 +0000 (Sun, 05 May 2013) Log Message: ----------- update Modified Paths: -------------- trunk/mmex/src/util.cpp Modified: trunk/mmex/src/util.cpp =================================================================== --- trunk/mmex/src/util.cpp 2013-05-05 12:23:19 UTC (rev 3852) +++ trunk/mmex/src/util.cpp 2013-05-05 12:46:25 UTC (rev 3853) @@ -404,78 +404,71 @@ return tipsStr; } -wxString DisplayDate2FormatDate(wxString strDate) +//*--------------------------------------------------------------------------*// +std::map<wxString,wxString> date_formats_map() { - int i = date_format().Index(strDate.Upper()); - if (i == wxNOT_FOUND) - return strDate; - return date_format_mask()[i]; + std::map<wxString, wxString> date_formats; + date_formats["%d/%m/%y"]="DD/MM/YY"; + date_formats["%d/%m/%Y"]="DD/MM/YYYY"; + date_formats["%d-%m-%y"]="DD-MM-YY"; + date_formats["%d-%m-%Y"]="DD-MM-YYYY"; + date_formats["%d.%m.%y"]="DD.MM.YY"; + date_formats["%d.%m.%Y"]="DD.MM.YYYY"; + date_formats["%d,%m,%y"]="DD,MM,YY"; + date_formats["%d/%m'%Y"]="DD/MM'YYYY"; + date_formats["%d/%m %Y"]="DD/MM YYYY"; + date_formats["%m/%d/%y"]="MM/DD/YY"; + date_formats["%m/%d/%Y"]="MM/DD/YYYY"; + date_formats["%m-%d-%y"]="MM-DD-YY"; + date_formats["%m-%d-%Y"]="MM-DD-YYYY"; + date_formats["%m/%d'%y"]="MM/DD'YY"; + date_formats["%m/%d'%Y"]="MM/DD'YYYY"; + date_formats["%y/%m/%d"]="YY/MM/DD"; + date_formats["%y-%m-%d"]="YY-MM-DD"; + date_formats["%Y/%m/%d"]="YYYY/MM/DD"; + date_formats["%Y-%m-%d"]="YYYY-MM-DD"; + date_formats["%Y.%m.%d"]="YYYY.MM.DD"; + date_formats["%Y%m%d"]="YYYYMMDD"; + + return date_formats; } -wxString FormatDate2DisplayDate(wxString strDate) +wxString DisplayDate2FormatDate(const wxString sDateMask) { - int i = date_format_mask().Index(strDate); - if (i == wxNOT_FOUND) i = 0; - return date_format()[i]; + for (const auto& date_mask: date_formats_map()) + { + if (date_mask.second == sDateMask) return date_mask.first; + }; + wxASSERT(false); + return mmex::DEFDATEFORMAT; } +wxString FormatDate2DisplayDate(const wxString sDateMask) +{ + return date_formats_map()[sDateMask]; +} + const wxArrayString date_format_mask() { wxArrayString mask; - - mask.Add("%d/%m/%y"); - mask.Add("%d/%m/%Y"); - mask.Add("%d-%m-%y"); - mask.Add("%d-%m-%Y"); - mask.Add("%d.%m.%y"); - mask.Add("%d.%m.%Y"); - mask.Add("%d,%m,%y"); - mask.Add("%d/%m'%Y"); - mask.Add("%d/%m %Y"); - mask.Add("%m/%d/%y"); - mask.Add("%m/%d/%Y"); - mask.Add("%m-%d-%y"); - mask.Add("%m-%d-%Y"); - mask.Add("%m/%d'%y"); - mask.Add("%m/%d'%Y"); - mask.Add("%y/%m/%d"); - mask.Add("%y-%m-%d"); - mask.Add("%Y/%m/%d"); - mask.Add("%Y-%m-%d"); - mask.Add("%Y.%m.%d"); - mask.Add("%Y%m%d"); - + for (const auto& date_mask: date_formats_map()) + { + mask.Add(date_mask.first); + }; return mask; } const wxArrayString date_format() { - wxArrayString date_format; + wxArrayString format; + for (const auto& date_mask: date_formats_map()) + { + format.Add(date_mask.second); + }; + return format; - date_format.Add("DD/MM/YY"); - date_format.Add("DD/MM/YYYY"); - date_format.Add("DD-MM-YY"); - date_format.Add("DD-MM-YYYY"); - date_format.Add("DD.MM.YY"); - date_format.Add("DD.MM.YYYY"); - date_format.Add("DD,MM,YY"); - date_format.Add("DD/MM'YYYY"); - date_format.Add("DD/MM YYYY"); - date_format.Add("MM/DD/YY"); - date_format.Add("MM/DD/YYYY"); - date_format.Add("MM-DD-YY"); - date_format.Add("MM-DD-YYYY"); - date_format.Add("MM/DD'YY"); - date_format.Add("MM/DD'YYYY"); - date_format.Add("YY/MM/DD"); - date_format.Add("YY-MM-DD"); - date_format.Add("YYYY/MM/DD"); - date_format.Add("YYYY-MM-DD"); - date_format.Add("YYYY.MM.DD"); - date_format.Add("YYYYMMDD"); - - return date_format; } +//*--------------------------------------------------------------------------*// // FIXME: Freeze - Thaw is ok for wx2.8.x but not for wx2.9.x // Located here as a function to allow removal in WXGTK This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vo...@us...> - 2013-05-09 12:56:43
|
Revision: 3869 http://sourceforge.net/p/moneymanagerex/code/3869 Author: vomikan Date: 2013-05-09 12:56:40 +0000 (Thu, 09 May 2013) Log Message: ----------- mmGetColourFromString function updated. wxRegEx usage Modified Paths: -------------- trunk/mmex/src/util.cpp Modified: trunk/mmex/src/util.cpp =================================================================== --- trunk/mmex/src/util.cpp 2013-05-09 11:16:28 UTC (rev 3868) +++ trunk/mmex/src/util.cpp 2013-05-09 12:56:40 UTC (rev 3869) @@ -290,36 +290,29 @@ wxColour mmGetColourFromString(const wxString& str) { - wxStringTokenizer tkz(str, ",", wxTOKEN_RET_EMPTY_ALL); - unsigned char red = 0xFF; - unsigned char blue = 0xFF; - unsigned char green = 0xFF; - - if (tkz.HasMoreTokens()) + wxColor color = wxNullColour; + wxRegEx pattern = "([0-9]{1,3})([,])([0-9]{1,3})([,])([0-9]{1,3})"; + if (pattern.Matches(str)) { - long longVal; - tkz.GetNextToken().ToLong(&longVal); - red = longVal; + wxString red = pattern.GetMatch(str, 1); + wxString green = pattern.GetMatch(str, 3); + wxString blue = pattern.GetMatch(str, 5); - if (tkz.HasMoreTokens()) - { - tkz.GetNextToken().ToLong(&longVal); - green = longVal; - - if (tkz.HasMoreTokens()) - { - tkz.GetNextToken().ToLong(&longVal); - blue = longVal; - } - } + color = wxColour(wxAtoi(red), wxAtoi(green), wxAtoi(blue)); } - - return wxColour(red, green, blue); + else + { + color = wxColor(str); + } + return color; } wxString mmGetStringFromColour(wxColour color) { + //TODO: In next releases color settings wtring may be changed + //return color.GetAsString(wxC2S_HTML_SYNTAX); return wxString::Format("%d,%d,%d", color.Red(), color.Green(), color.Blue()); + } void mmLoadColorsFromDatabase(std::shared_ptr<MMEX_IniSettings> pIniSettings) @@ -425,17 +418,17 @@ date_formats["%Y.%m.%d"]="YYYY.MM.DD"; date_formats["%Y%m%d"]="YYYYMMDD"; - return date_formats; + return date_formats; } wxString DisplayDate2FormatDate(const wxString sDateMask) { for (const auto& date_mask: date_formats_map()) { - if (date_mask.second == sDateMask) return date_mask.first; - }; - wxASSERT(false); - return mmex::DEFDATEFORMAT; + if (date_mask.second == sDateMask) return date_mask.first; + }; + wxASSERT(false); + return mmex::DEFDATEFORMAT; } wxString FormatDate2DisplayDate(const wxString sDateMask) @@ -448,8 +441,8 @@ wxArrayString mask; for (const auto& date_mask: date_formats_map()) { - mask.Add(date_mask.first); - }; + mask.Add(date_mask.first); + }; return mask; } @@ -458,8 +451,8 @@ wxArrayString format; for (const auto& date_mask: date_formats_map()) { - format.Add(date_mask.second); - }; + format.Add(date_mask.second); + }; return format; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <vo...@us...> - 2013-05-10 19:37:58
|
Revision: 3878 http://sourceforge.net/p/moneymanagerex/code/3878 Author: vomikan Date: 2013-05-10 19:37:55 +0000 (Fri, 10 May 2013) Log Message: ----------- fix error: conversion from ?\226?\128?\152const char [47]?\226?\128?\153 to non-scalar type ?\226?\128?\152wxRegEx?\226?\128?\153 requested Modified Paths: -------------- trunk/mmex/src/util.cpp Modified: trunk/mmex/src/util.cpp =================================================================== --- trunk/mmex/src/util.cpp 2013-05-10 18:36:29 UTC (rev 3877) +++ trunk/mmex/src/util.cpp 2013-05-10 19:37:55 UTC (rev 3878) @@ -291,12 +291,12 @@ wxColour mmGetColourFromString(const wxString& str) { wxColor color = wxNullColour; - wxRegEx pattern = "([0-9]{1,3})([,])([0-9]{1,3})([,])([0-9]{1,3})"; + wxRegEx pattern("([0-9]{1,3}),([0-9]{1,3}),([0-9]{1,3})"); if (pattern.Matches(str)) { wxString red = pattern.GetMatch(str, 1); - wxString green = pattern.GetMatch(str, 3); - wxString blue = pattern.GetMatch(str, 5); + wxString green = pattern.GetMatch(str, 2); + wxString blue = pattern.GetMatch(str, 3); color = wxColour(wxAtoi(red), wxAtoi(green), wxAtoi(blue)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |