src/share/vm/utilities/ostream.cpp

changeset 535
c7c777385a15
parent 435
a61af66fc99e
child 537
f96100ac3d12
     1.1 --- a/src/share/vm/utilities/ostream.cpp	Fri Mar 28 09:00:39 2008 -0700
     1.2 +++ b/src/share/vm/utilities/ostream.cpp	Wed Apr 02 12:09:59 2008 -0700
     1.3 @@ -52,8 +52,9 @@
     1.4        _precount += _position + 1;
     1.5        _position = 0;
     1.6      } else if (ch == '\t') {
     1.7 -      _position += 8;
     1.8 -      _precount -= 7;  // invariant:  _precount + _position == total count
     1.9 +      int tw = 8 - (_position & 7);
    1.10 +      _position += tw;
    1.11 +      _precount -= tw-1;  // invariant:  _precount + _position == total count
    1.12      } else {
    1.13        _position += 1;
    1.14      }
    1.15 @@ -133,7 +134,17 @@
    1.16  }
    1.17  
    1.18  void outputStream::fill_to(int col) {
    1.19 -  while (position() < col) sp();
    1.20 +  int need_fill = col - position();
    1.21 +  sp(need_fill);
    1.22 +}
    1.23 +
    1.24 +void outputStream::move_to(int col, int slop, int min_space) {
    1.25 +  if (position() >= col + slop)
    1.26 +    cr();
    1.27 +  int need_fill = col - position();
    1.28 +  if (need_fill < min_space)
    1.29 +    need_fill = min_space;
    1.30 +  sp(need_fill);
    1.31  }
    1.32  
    1.33  void outputStream::put(char ch) {
    1.34 @@ -142,8 +153,23 @@
    1.35    write(buf, 1);
    1.36  }
    1.37  
    1.38 -void outputStream::sp() {
    1.39 -  this->write(" ", 1);
    1.40 +#define SP_USE_TABS false
    1.41 +
    1.42 +void outputStream::sp(int count) {
    1.43 +  if (count < 0)  return;
    1.44 +  if (SP_USE_TABS && count >= 8) {
    1.45 +    int target = position() + count;
    1.46 +    while (count >= 8) {
    1.47 +      this->write("\t", 1);
    1.48 +      count -= 8;
    1.49 +    }
    1.50 +    count = target - position();
    1.51 +  }
    1.52 +  while (count > 0) {
    1.53 +    int nw = (count > 8) ? 8 : count;
    1.54 +    this->write("        ", nw);
    1.55 +    count -= nw;
    1.56 +  }
    1.57  }
    1.58  
    1.59  void outputStream::cr() {

mercurial