|
htmlText
Encoded text class | [Previous] [Main] [Next] |
| htmlText encapsulates regular ASCII text, automatically encoding special characters during output so that they will be displayed correctly by browsers. The following symbols and their encoded equivalents appear below:
| |
| < <
| |
| > >
| |
| & &
| |
| " "
| |
|
| |
| By default, all String objects passed as arguments to html++ methods are stored internally as htmlText objects, unless first encapsulated using htmlLiteral.
| |
|
| |
| #include <dcmicro/htmlpp/text.h>
| |
|
| |
|
| |
| htmlLiteral, htmlNoBreak
| |
|
| |
| None.
| |
|
| |
| htmlText()
| |
| Constructs an empty object.
| |
|
| |
| htmlText( const String& text )
| |
| Constructs an object, inserting the string text into it.
| |
|
| |
| htmlText( const htmlText& rhs )
| |
| Copy constructor.
| |
|
| |
| virtual ~htmlText()
| |
| Destroys the object.
| |
|
| |
| = | htmlText& operator= ( const htmlText& rhs )
| |
| Replaces object contents with rhs, and returns a reference to it.
| |
|
| |
| = | htmlText& operator= ( const String& text )
| |
| Replaces object contents with text, and returns a reference to it.
| |
|
| |
| << | htmlText& operator<< ( const String& text )
| |
| Appends text, then returns a reference to the object.
| |
|
| |
| (String) | htmlText& operator String() const
| |
| Return the encoded text for the object as a string.
| |
|
| |
| RawText | String RawText() const
| |
| Return the unencoded text for the object as a string.
| |
|
| |
| EncodedText | String EncodedText() const
| |
| Return the encoded text for the object as a string. Same as the String operator.
| |
|
| |
| void Print( ostream& os ) const
| ||
| Outputs the object to os.
| |
|
| |
| Clone | htmlObject FAR * Clone() const
| |
| Returns a base-class pointer to a deep copy of the object.
| |
|
| |
|
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| int main( void )
| |
| {
| |
| htmlCgi server ;
| |
| htmlPage page( "html++ example application" ) ;
| |
|
| |
| // Regular text containing symbols
| |
| String symbol_text = " < > & \" " ;
| |
|
| |
| String encoded_text ;
| |
| encoded_text << htmlText( symbol_text ) ;
| |
|
| |
| page << "Demo of literal vs. encoded text"
| |
| << htmlBreak()
| |
| << htmlBreak() ;
| |
|
| |
| page << "The first two lines produce different "
| |
| "HTML code, but are interpreted "
| |
| "identically by the browser. The third "
| |
| "line shows how HTML codes can be "
| |
| "encoded for display."
| |
| << htmlBreak() ;
| |
|
| |
| htmlBlockQuote block ;
| |
| block << htmlLiteral( symbol_text )
| |
| << htmlBreak()
| |
| << htmlText( symbol_text )
| |
| << htmlBreak()
| |
| << htmlText( encoded_text )
| |
| << htmlBreak() ;
| |
|
| |
| page << block ;
| |
|
| |
| server << page ;
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
| Content-Type: text/html
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ example application</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| Demonstration of literal vs. encoded text<BR>
| |
| <BR>
| |
| The first two lines produce different HTML code, but are interpreted identically by the browser. The third line shows how HTML codes can be encoded for display.<BR>
| |
| <BLOCKQUOTE>
| |
| < > & " <BR>
| |
| < > & " <BR>
| |
| &lt; &gt; &amp; &quot; <BR>
| |
| </BLOCKQUOTE>
| |
| </BODY>
| |
| </HTML>
| |
|
| |
|
| |
| |
|
| |
|
| |
|
| |
| // Example of using htmlFont to produce an
| |
| // htmlText-derived class that automatically
| |
| // enlarges the first character.
| |
| #include <stdio.h>
| |
| #include <stdlib.h>
| |
| #include <dcmicro/htmlpp/htmlpp.h>
| |
|
| |
| //
| |
| // Definition of our new class. Note how the
| |
| // constructors are all inline functions that
| |
| // simply call the parent-class constructors.
| |
| //
| |
| class FancyText : public htmlText
| |
| {
| |
| public :
| |
| FancyText() : htmlText() {} ;
| |
| FancyText( const String& text ) : htmlText(text) {} ;
| |
| FancyText( const htmlText& rhs ) : htmlText( rhs ) {} ;
| |
|
| |
| void Print( ostream& os ) const ;
| |
| htmlObject FAR * Clone() const { return new FancyText(*this) ; }
| |
| } ;
| |
|
| |
| //
| |
| // Our overriden Print() method does
| |
| // all the work.
| |
| //
| |
| void FancyText :: Print( ostream &os ) const
| |
| {
| |
| PrintStart( os ) ;
| |
|
| |
| // Get the string that would normally
| |
| // be output.
| |
| String s = EncodedText() ;
| |
|
| |
| // Get the first character and insert it
| |
| // into the large font object.
| |
| htmlFont large( "", +2 ) ;
| |
| large = s.Left(1) ;
| |
|
| |
| // Output the large character followed
| |
| // by the rest of the text.
| |
| os << large << s.Right( s.GetLength() - 1 ) ;
| |
|
| |
| PrintEnd( os ) ;
| |
| }
| |
|
| |
|
| |
| int main( void )
| |
| {
| |
| htmlPage page( "html++ example application" ) ;
| |
|
| |
| // Our FancyText class can be used anywhere
| |
| // that htmlText can.
| |
| FancyText t1( "Four score and seven years ago..." ) ;
| |
|
| |
| FancyText t2( "In the beginning, God created the heavans and the earth..." ) ;
| |
|
| |
| page << htmlParagraph( t1 )
| |
| << htmlParagraph( t2 ) ;
| |
|
| |
| cout << page ;
| |
|
| |
| return 0 ;
| |
| }
| |
|
| |
|
| |
| <HTML>
| |
| <HEAD>
| |
| <TITLE>html++ example application</TITLE>
| |
| </HEAD>
| |
| <BODY>
| |
| <P><FONT SIZE="+2">F</FONT>our score and seven years ago...</P>
| |
| <P><FONT SIZE="+2">I</FONT>n the beginning, God created the heavens and the earth...</P>
| |
| </BODY>
| |
| </HTML>
| |
|
| |
| |
