00001
00002
00003 #include "fit_text.h"
00004 #include "safe_assign.h"
00005
00006 fit_text::fit_text(const char* str, const char* ellipsis)
00007 {
00008 safe_assign(m_text, str);
00009 safe_assign(m_ellipsis, ellipsis);
00010 }
00011
00012 std::ostream& operator<< (std::ostream &os, const fit_text& ft)
00013 {
00014 int width = os.width();
00015 if ((int)ft.m_text.size() > width)
00016 {
00017 int ellipsissize = (int)ft.m_ellipsis.size();
00018 std::string s;
00019 int p = (width-ellipsissize)/2;
00020 if (p >= 1)
00021 {
00022 s.append(ft.m_text, 0, p);
00023 s.append(ft.m_ellipsis);
00024 if (width-ellipsissize-2*p > 0)
00025 p++;
00026 s.append(ft.m_text, ft.m_text.size()-p, p);
00027 }
00028 else
00029 {
00030 s.append(ft.m_text, 0, width);
00031 }
00032 os << s;
00033 }
00034 else
00035 {
00036 os << ft.m_text;
00037 }
00038 return os;
00039 }
00040