From b3299ecd73358d501ddf57e83946d1f276eb13d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 22 Jan 2014 00:10:49 +0100 Subject: [PATCH] Paragraph: Added simple PrintToStream(). --- src/apps/haiku-depot/textview/Paragraph.cpp | 26 ++++++++++++++++++++- src/apps/haiku-depot/textview/Paragraph.h | 4 +++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/apps/haiku-depot/textview/Paragraph.cpp b/src/apps/haiku-depot/textview/Paragraph.cpp index 3543b80170..d15a0de892 100644 --- a/src/apps/haiku-depot/textview/Paragraph.cpp +++ b/src/apps/haiku-depot/textview/Paragraph.cpp @@ -1,11 +1,12 @@ /* - * Copyright 2013, Stephan Aßmus . + * Copyright 2013-2014, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #include "Paragraph.h" #include +#include Paragraph::Paragraph() @@ -268,3 +269,26 @@ Paragraph::GetText(int32 start, int32 length) const return text; } + + +void +Paragraph::PrintToStream() const +{ + int32 spanCount = fTextSpans.CountItems(); + if (spanCount == 0) { + printf("

\n"); + return; + } + printf("

\n"); + for (int32 i = 0; i < spanCount; i++) { + const TextSpan& span = fTextSpans.ItemAtFast(i); + if (span.CountChars() == 0) + printf(" \n"); + else { + BString text = span.Text(); + text.ReplaceAll("\n", "\\n"); + printf(" %s\n", text.String()); + } + } + printf("

\n"); +} diff --git a/src/apps/haiku-depot/textview/Paragraph.h b/src/apps/haiku-depot/textview/Paragraph.h index 6685a9e225..a9f16b3916 100644 --- a/src/apps/haiku-depot/textview/Paragraph.h +++ b/src/apps/haiku-depot/textview/Paragraph.h @@ -1,5 +1,5 @@ /* - * Copyright 2013, Stephan Aßmus . + * Copyright 2013-2014, Stephan Aßmus . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PARAGRAPH_H @@ -41,6 +41,8 @@ public: BString GetText(int32 start, int32 length) const; + void PrintToStream() const; + private: ParagraphStyle fStyle; TextSpanList fTextSpans;