[Aptitude-svn-commit] r3405 - in branches/aptitude-0.3/aptitude: . src/vscreen src/vscreen/config
Daniel Burrows
dburrows@costa.debian.org
Wed, 15 Jun 2005 18:46:23 +0000
Author: dburrows
Date: Wed Jun 15 18:46:21 2005
New Revision: 3405
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/vscreen/config/style.h
branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc
branches/aptitude-0.3/aptitude/src/vscreen/curses++.h
Log:
Add a chstring-analogue for wide characters.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Wed Jun 15 18:46:21 2005
@@ -1,3 +1,11 @@
+2005-06-15 Daniel Burrows <dburrows@debian.org>
+
+ * src/vscreen/config/style.h, src/vscreen/curses++.cc, src/vscreen/curses++.h:
+
+ Add definitions of a chstring-analogue for wide-characters (it
+ stores wide characters combined with attributes). Currently this
+ isn't used anywhere; that's the next step of UTF8ization.
+
2005-06-15 Jens Seidel <jensseidel@users.sf.net>
* Spellcheck German translation
Modified: branches/aptitude-0.3/aptitude/src/vscreen/config/style.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/config/style.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/config/style.h Wed Jun 15 18:46:21 2005
@@ -22,6 +22,8 @@
#include <ncursesw/curses.h>
+#include "../curses++.h" // For wchtype.
+
#include <string>
#include "colors.h"
@@ -169,6 +171,17 @@
mix_color(ch, fg, bg) |
((((ch & ~ (A_CHARTEXT | A_COLOR)) | set_attrs) & ~clear_attrs) ^ flip_attrs);
}
+
+ /** \return the given character with its attributes updated with ours. */
+ wchtype apply_to(wchtype ch) const
+ {
+ // Relies somewhat on the bitwise representation of attributes;
+ // the multicharacter-capable stuff needed for utf8 will make this
+ // go away (for better or for worse..)
+ return wchtype(ch.ch,
+ mix_color(ch.attrs, fg, bg) |
+ ((((ch.attrs & ~ A_COLOR) | set_attrs) & ~clear_attrs) ^ flip_attrs));
+ }
};
// To allow styles to be built functionally, the following
Modified: branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/curses++.cc Wed Jun 15 18:46:21 2005
@@ -62,6 +62,30 @@
*i=st.apply_to(*i);
}
+wchstring::wchstring(const wstring &s)
+{
+ (*this)=s;
+}
+
+wchstring::wchstring(const wstring &s, const style &st)
+{
+ (*this)=s;
+ apply_style(st);
+}
+
+wchstring::wchstring(const wchstring &s, const style &st)
+ :super(s)
+{
+ (*this)=s;
+ apply_style(st);
+}
+
+void wchstring::apply_style(const style &st)
+{
+ for(iterator i=begin(); i!=end(); ++i)
+ *i=st.apply_to(*i);
+}
+
int char_traits<chtype>::compare(const chtype *s1,
const chtype *s2,
size_t n)
@@ -113,6 +137,57 @@
return s;
}
+int char_traits<wchtype>::compare(const wchtype *s1,
+ const wchtype *s2,
+ size_t n)
+{
+ const wchtype *s1end=s1+n;
+
+ while(s1!=s1end)
+ {
+ wchtype c1=*s1;
+ wchtype c2=*s2;
+
+ if(c1<c2)
+ return -1;
+ else if(c1>c2)
+ return 1;
+
+ ++s1;
+ ++s2;
+ }
+
+ return 0;
+}
+
+size_t char_traits<wchtype>::length (const char_type* s)
+{
+ size_t rval=0;
+
+ while(*s!=eos())
+ {
+ ++rval;
+ ++s;
+ }
+
+ return rval;
+}
+
+wchtype *char_traits<wchtype>::assign(char_type *s,
+ size_t n,
+ const char_type &c)
+{
+ char_type *ends=s+n;
+
+ while(s!=ends)
+ {
+ *s=c;
+ ++s;
+ }
+
+ return s;
+}
+
chstring &chstring::operator=(const std::string &s)
{
erase();
Modified: branches/aptitude-0.3/aptitude/src/vscreen/curses++.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/curses++.h (original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/curses++.h Wed Jun 15 18:46:21 2005
@@ -32,6 +32,70 @@
#include "../../config.h"
+/** A structure that amalgamates a wchar_t together with attributes.
+ * This is similar to cchar_t, but has the advantage of having
+ * well-defined properties and behavior; the routines to manipulate
+ * cchar_t's are vaguely documented and a lot of their behavior has
+ * to be guessed at or inferred from source code. I don't trust
+ * interfaces where I have to guess at their behavior, and I think
+ * that I won't lose too much efficiency by doing things this way.
+ */
+struct wchtype
+{
+ /** The character value associated with this string. This code
+ * presently assumes that wchar_t is large enough to hold any *
+ * single Unicode (UCS-4) character, which is ok for GNU but might
+ * not port * everywhere. However, I do guarantee that any
+ * adjustments made * to compensate for this nonportability will
+ * not change the external interface of wchtype.
+ */
+ wchar_t ch;
+
+ /** The text attributes (including color) associated with this
+ * character.
+ */
+ attr_t attrs;
+
+ wchtype()
+ {
+ }
+
+ wchtype(const wchar_t &_ch, const attr_t &_attrs)
+ :ch(_ch), attrs(_attrs)
+ {
+ }
+
+ bool operator==(const wchtype &other) const
+ {
+ return ch==other.ch && attrs==other.attrs;
+ }
+
+ bool operator!=(const wchtype &other) const
+ {
+ return ch!=other.ch || attrs!=other.attrs;
+ }
+
+ bool operator<(const wchtype &other) const
+ {
+ return ch<other.ch || ch==other.ch && attrs<other.attrs;
+ }
+
+ bool operator<=(const wchtype &other) const
+ {
+ return (*this) == other || (*this) < other;
+ }
+
+ bool operator>(const wchtype &other) const
+ {
+ return !((*this)<=other);
+ }
+
+ bool operator>=(const wchtype &other) const
+ {
+ return !((*this)<other);
+ }
+};
+
/** Based on libstdc++-3's instantiation of this for characters.
*
* This could do something clever, such as changing comparisons to
@@ -65,6 +129,30 @@
{ return (char_type*) memmove (s1, s2, n*sizeof(char_type)); }
static char_type* assign (char_type* s1, size_t n, const char_type& c);
};
+
+ template <>
+ struct TRAITS_CLASS<wchtype> {
+ typedef wchtype char_type;
+
+ static void assign (char_type& c1, const char_type& c2)
+ { c1 = c2; }
+ static bool eq (const char_type & c1, const char_type& c2)
+ { return (c1 == c2); }
+ static bool ne (const char_type& c1, const char_type& c2)
+ { return (c1 != c2); }
+ static bool lt (const char_type& c1, const char_type& c2)
+ { return (c1 < c2); }
+ static char_type eos () { return wchtype(0,0); }
+ static bool is_del(char_type a) { return isspace(a.ch); }
+
+ static int compare (const char_type* s1, const char_type* s2, size_t n);
+ static size_t length (const char_type* s);
+ static char_type* copy (char_type* s1, const char_type* s2, size_t n)
+ { return (char_type*) memcpy (s1, s2, n*sizeof(char_type)); }
+ static char_type* move (char_type* s1, const char_type* s2, size_t n)
+ { return (char_type*) memmove (s1, s2, n*sizeof(char_type)); }
+ static char_type* assign (char_type* s1, size_t n, const char_type& c);
+ };
}
class style;
@@ -103,6 +191,36 @@
void apply_style(const style &st);
};
+class wchstring:public std::basic_string<wchtype>
+{
+ typedef std::basic_string<wchtype> super;
+public:
+ wchstring(const std::basic_string<wchtype> &s)
+ :std::basic_string<wchtype>(s) {}
+
+ /** Create a new wchstring with empty attribute information. */
+ wchstring(const std::wstring &s);
+ wchstring(const std::wstring &s, const style &st);
+
+ wchstring(const wchstring &s):super(s) {}
+ /** Apply the given style to the given chstring, and set ourselves
+ * to the result.
+ */
+ wchstring(const wchstring &s, const style &st);
+
+ wchstring(const wchstring &s, size_t loc, size_t n=npos)
+ :super(s, loc, n) {}
+
+ wchstring(size_t n, wchtype c)
+ :super(n, c) {}
+
+ /** Assign the characters of s to this, setting all attributes to A_NORMAL. */
+ chstring &operator=(const std::wstring &s);
+
+ /** Change the attributes of this string by using the given style. */
+ void apply_style(const style &st);
+};
+
inline chtype _getbkgd(WINDOW *win)
{
return getbkgd(win);