summaryrefslogtreecommitdiff
path: root/cpp/src/Slice/OutputUtil.cpp
diff options
context:
space:
mode:
authorZeroC Staff <git@zeroc.com>2001-07-25 19:48:36 +0000
committerZeroC Staff <git@zeroc.com>2001-07-25 19:48:36 +0000
commit76e6f638ac9fbd902dcc7a30f5a6cbf71862f4dd (patch)
tree2e54b287750443c3313701a78e1a968a02c1ce40 /cpp/src/Slice/OutputUtil.cpp
parentfixes (diff)
downloadice-76e6f638ac9fbd902dcc7a30f5a6cbf71862f4dd.tar.bz2
ice-76e6f638ac9fbd902dcc7a30f5a6cbf71862f4dd.tar.xz
ice-76e6f638ac9fbd902dcc7a30f5a6cbf71862f4dd.zip
added support for spaces, variable block start/end text and variable indent
sizes
Diffstat (limited to 'cpp/src/Slice/OutputUtil.cpp')
-rw-r--r--cpp/src/Slice/OutputUtil.cpp88
1 files changed, 66 insertions, 22 deletions
diff --git a/cpp/src/Slice/OutputUtil.cpp b/cpp/src/Slice/OutputUtil.cpp
index 091c5e7bfec..dbf20e5ac61 100644
--- a/cpp/src/Slice/OutputUtil.cpp
+++ b/cpp/src/Slice/OutputUtil.cpp
@@ -31,14 +31,22 @@ Separator sp;
Slice::Output::Output()
: pos_(0),
indent_(0),
- separator_(true)
+ separator_(true),
+ _blockStart("{"),
+ _blockEnd("}"),
+ _useTab(true),
+ _indentSize(4)
{
}
Slice::Output::Output(const char* s)
: pos_(0),
indent_(0),
- separator_(true)
+ separator_(true),
+ _blockStart("{"),
+ _blockEnd("}"),
+ _useTab(true),
+ _indentSize(4)
{
open(s);
}
@@ -54,10 +62,10 @@ Slice::Output::print(const char* s)
{
for(unsigned int i = 0; i < strlen(s); ++i)
{
- if(s[i] == '\n')
- pos_ = 0;
- else
- ++pos_;
+ if(s[i] == '\n')
+ pos_ = 0;
+ else
+ ++pos_;
}
out_ << s;
@@ -66,15 +74,15 @@ Slice::Output::print(const char* s)
void
Slice::Output::inc()
{
- indent_ += 4;
+ indent_ += _indentSize;
separator_ = true;
}
void
Slice::Output::dec()
{
- assert(indent_ >= 4);
- indent_ -= 4;
+ assert(indent_ >= _indentSize);
+ indent_ -= _indentSize;
separator_ = true;
}
@@ -99,6 +107,30 @@ Slice::Output::restoreIndent()
indent_ = indentSave_.top();
indentSave_.pop();
}
+
+void
+Slice::Output::setBeginBlock(const char *bb)
+{
+ _blockStart = bb;
+}
+
+void
+Slice::Output::setEndBlock(const char *eb)
+{
+ _blockEnd = eb;
+}
+
+void
+Slice::Output::setIndent(int indentSize)
+{
+ _indentSize = indentSize;
+}
+
+void
+Slice::Output::setUseTab(bool useTab)
+{
+ _useTab = useTab;
+}
void
Slice::Output::nl()
@@ -108,19 +140,31 @@ Slice::Output::nl()
separator_ = true;
int indent = indent_;
-
- while(indent >= 8)
- {
- indent -= 8;
- out_ << "\t";
- pos_ += 8;
- }
+
+ if (_useTab)
+ {
+ while(indent >= 8)
+ {
+ indent -= 8;
+ out_ << '\t';
+ pos_ += 8;
+ }
+ }
+ else
+ {
+ while(indent >= _indentSize)
+ {
+ indent -= indentSize;
+ out_ << " ";
+ pos_ += _indentSize;
+ }
+ }
while(indent > 0)
{
- --indent;
- out_ << ' ';
- ++pos_;
+ --indent;
+ out_ << ' ';
+ ++pos_;
}
out_.flush();
@@ -130,7 +174,7 @@ void
Slice::Output::sb()
{
nl();
- out_ << '{';
+ out_ << _blockStart;
++pos_;
inc();
separator_ = false;
@@ -141,7 +185,7 @@ Slice::Output::eb()
{
dec();
nl();
- out_ << '}';
+ out_ << _blockEnd;
--pos_;
}
@@ -149,7 +193,7 @@ void
Slice::Output::sp()
{
if(separator_)
- out_ << '\n';
+ out_ << '\n';
}
bool