This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Small patch for bastring.cc
- To: egcs-patches at egcs dot cygnus dot com
- Subject: Small patch for bastring.cc
- From: John Allen <john dot allen at maotech dot ie>
- Date: Sat, 27 Mar 1999 12:55:31 +0000
- Organization: MAO Technologies LLC.
This patch adds field width, and left & right justification to the
ostarem<<() operator of the basic_string<> template.
This patch is against the bastring.cc source in the 1.1.2 release,
and was generated with "diff -up"
I have not filled in the Copyright Assignment, as this is only
a minor patch.
I hereby assign copyright of this patch to the FSF.
BFN
--
John Allen email: john.allen@maotech.ie
MAO Technologies LLC. www: http://www.maotech.ie
Creators of LinuxMT phone: intl+353-862315986
--- /tmp/egcs-1.1.2/libstdc++/std/bastring.cc Sun Jul 12 02:20:51 1998
+++ bastring.cc Sat Mar 27 12:28:23 1999
@@ -463,11 +463,56 @@ operator>> (istream &is, basic_string <c
return is;
}
+inline int bstring_pad(ostream& o, char fill, int pad)
+{
+ int count = 0;
+
+ while (o.good() && pad--)
+ {
+ o << fill;
+ count++;
+ }
+
+ return count;
+}
+
template <class charT, class traits, class Allocator>
ostream &
operator<< (ostream &o, const basic_string <charT, traits, Allocator>& s)
{
- return o.write (s.data (), s.length ());
+ int len = s.length();
+ int w = o.width(0);
+
+ if (w && len > w)
+ {
+ len = w;
+ }
+
+ char fill_char = o.fill();
+ int padding = w > len ? w - len : 0;
+
+ if (!(o.flags() & ios::left) && padding > 0) // Default adjustment.
+ {
+ if (bstring_pad(o, fill_char, padding) != padding)
+ {
+ o.set(ios::badbit);
+ goto failed;
+ }
+ }
+
+ o.write(s.data(), len);
+
+ if (o.flags() & ios::left && padding > 0) // Left adjustment.
+ {
+ if (bstring_pad(o, fill_char, padding) != padding)
+ {
+ o.set(ios::badbit);
+ goto failed;
+ }
+ }
+
+failed:
+ return o;
}
template <class charT, class traits, class Allocator>