libkdenetwork Library API Documentation

LinkLocator Class Reference

LinkLocator assists in identifying sections of text that can usefully be converted in hyperlinks in html.Identifies URLs and email addresses embedded in plaintext. More...

#include <linklocator.h>

Collaboration diagram for LinkLocator:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 LinkLocator (const QString &text, int pos=0)
void setMaxUrlLen (int length)
int maxUrlLen () const
void setMaxAddressLen (int length)
int maxAddressLen () const
QString getUrl ()
QString getEmailAddress ()

Static Public Member Functions

static QString convertToHtml (const QString &plainText, bool preserveBlanks=false, int maxUrlLen=4096, int maxAddressLen=255)

Protected Attributes

QString mText
int mPos

Detailed Description

LinkLocator assists in identifying sections of text that can usefully be converted in hyperlinks in html.Identifies URLs and email addresses embedded in plaintext.

It is intended to be used in two ways: either by calling convertToHtml() to convert a plaintext string into html, or to be derived from where more control is needed.

Author:
Dave Corrie <kde@davecorrie.com>

Definition at line 38 of file linklocator.h.


Constructor & Destructor Documentation

LinkLocator::LinkLocator const QString text,
int  pos = 0
 

Constructs a LinkLocator that will search a plaintext string from a given starting point.

Parameters:
text The string in which to search.
pos An index into 'text' from where the search should begin.

Definition at line 26 of file linklocator.cpp.


Member Function Documentation

void LinkLocator::setMaxUrlLen int  length  ) 
 

Sets the maximum length of URLs that will be matched by getUrl().

By default, this is set to 4096 characters. The reason for this limit is that there may be possible security implications in handling URLs of unlimited length.

Parameters:
length The new maximum length of URLs that will be matched by getUrl().

Definition at line 36 of file linklocator.cpp.

Referenced by convertToHtml().

int LinkLocator::maxUrlLen  )  const
 

Returns:
The current limit on the maximum length of a URL.
See also:
setMaxUrlLen().

Definition at line 41 of file linklocator.cpp.

Referenced by getUrl().

void LinkLocator::setMaxAddressLen int  length  ) 
 

Sets the maximum length of email addresses that will be matched by getEmailAddress().

By default, this is set to 255 characters. The reason for this limit is that there may be possible security implications in handling addresses of unlimited length.

Parameters:
length The new maximum length of email addresses that will be matched by getEmailAddress().

Definition at line 46 of file linklocator.cpp.

Referenced by convertToHtml().

int LinkLocator::maxAddressLen  )  const
 

Returns:
The current limit on the maximum length of an email address.
See also:
setMaxAddressLen().

Definition at line 51 of file linklocator.cpp.

Referenced by getEmailAddress().

QString LinkLocator::getUrl  ) 
 

Attempts to grab a URL starting at the current scan position.

If there is no URL at the current scan position, then an empty string is returned. If a URL is found, the current scan position is set to the index of the last character in the URL.

Returns:
The URL at the current scan position, or an empty string.

Definition at line 56 of file linklocator.cpp.

References maxUrlLen(), mPos, and mText.

Referenced by convertToHtml().

QString LinkLocator::getEmailAddress  ) 
 

Attempts to grab an email address.

If there is an @ symbol at the current scan position, then the text will be searched both backwards and forwards to find the email address. If there is no @ symbol at the current scan position, an empty string is returned. If an address is found, then the current scan position is set to the index of the last character in the address.

Returns:
The email address at the current scan position, or an empty string.

Definition at line 132 of file linklocator.cpp.

References maxAddressLen(), mPos, and mText.

Referenced by convertToHtml().

QString LinkLocator::convertToHtml const QString plainText,
bool  preserveBlanks = false,
int  maxUrlLen = 4096,
int  maxAddressLen = 255
[static]
 

Converts plaintext into html.

The following characters are converted to HTML entities: & " < >. Newlines are also preserved.

Parameters:
plainText The text to be converted into HTML.
preserveBlanks Whether to preserve the appearance of sequences of space characters and tab characters in the resulting HTML.
maxUrlLen The maximum length of permitted URLs. (See maxUrlLen().)
maxAddressLen The maximum length of permitted email addresses. (See maxAddressLen().)
Returns:
An HTML version of the text supplied in the 'plainText' parameter, suitable for inclusion in the BODY of an HTML document.

Definition at line 186 of file linklocator.cpp.

References getEmailAddress(), getUrl(), mPos, mText, setMaxAddressLen(), and setMaxUrlLen().


Member Data Documentation

QString LinkLocator::mText [protected]
 

The plaintext string being scanned for URLs and email addresses.

Definition at line 134 of file linklocator.h.

Referenced by convertToHtml(), getEmailAddress(), and getUrl().

int LinkLocator::mPos [protected]
 

The current scan position.

Definition at line 138 of file linklocator.h.

Referenced by convertToHtml(), getEmailAddress(), and getUrl().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for libkdenetwork Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:39:14 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003