Permalink
Browse files

Add original docs

  • Loading branch information...
1 parent 2d562d8 commit 141f957d3d62a88671d38e7cca769b44625ef218 @icefox committed Oct 28, 2009
Showing with 36 additions and 0 deletions.
  1. +36 −0 tst_guess.cpp
View
@@ -30,6 +30,42 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <qdiriterator.h>
#include <qurl.h>
+/*!
+ Returns a valid URL from a user supplied string if one can be deducted.
+ In the case that is not possible, an invalid QUrl() is returned.
+
+ \since 4.6
+
+ Most applications that can browse the web, allow the user to input a URL
+ in the form of a plain string. This string can be manually typed into
+ a location bar, obtained from the clipboard, or passed in via command
+ line arguments.
+
+ When the string is not already a valid URL, a best guess is performed,
+ making various web related assumptions.
+
+ In the case the string corresponds to a valid file path on the system,
+ a file:// URL is constructed, using QUrl::fromLocalFile().
+
+ If that is not the case, an attempt is made to turn the string into a
+ http:// or ftp:// URL. The latter in the case the string starts with
+ 'ftp'. The result is then passed through QUrl's tolerant parser, and
+ in the case or success, a valid QUrl is returned, orelse a QUrl().
+
+ Examples
+ - webkit.org becomes http://webkit.org
+ - ftp.webkit.org becomes ftp://ftp.webkit.org
+ - localhost becomes http://localhost
+ - /home/user/test.html becomes file:///home/user/test.html (if exists)
+
+ Tips when dealing with URLs and strings
+ - When creating a QString from a QByteArray or a char*, always use
+ QString::fromUtf8().
+ - Do not use QUrl(string), nor QUrl::toString() anywhere where the URL might
+ be used, such as in the location bar, as those functions loose data.
+ Instead use QUrl::fromEncoded() and QUrl::toEncoded(), respectively.
+
+*/
static QUrl guessUrlFromString(const QString &string)
{
QString trimmedString = string.trimmed();

0 comments on commit 141f957

Please sign in to comment.