[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: KURL Patch
From:       Carsten Pfeiffer <carpdjih () cetus ! zrz ! tu-berlin ! de>
Date:       2001-10-13 19:09:02
[Download RAW message or body]

On Samstag, 13. Oktober 2001 20:28 Frerich Raabe wrote:
> Hi,
>
> I attached a patch for kurl.* which adds a method 'queryValue()', making it
> possible to do stuff like
>
> KURL u = "http://www.foo.bar/yoyodyne.php?q1=a&q2=b";
> cout << u.queryItem("q1") << endl; // prints 'a'

If you have ?foobar=1?foo=2
then queryItem("foo") will return 1 instead of 2. And ?foo= should return "" 
instead of QString::null, I think.

Cheers
Carsten Pfeiffer
["patch" (text/x-diff)]

Index: kurl.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kurl.cpp,v
retrieving revision 1.172
diff -u -p -B -w -r1.172 kurl.cpp
--- kurl.cpp	2001/08/26 16:58:55	1.172
+++ kurl.cpp	2001/10/13 19:04:43
@@ -1575,3 +1575,28 @@ bool urlcmp( const QString& _url1, const
 
   return true;
 }
+
+QString KURL::queryValue( const QString& _item )
+{
+  if ( m_strQuery_encoded.length() <= 1 )
+    return QString::null;
+
+  QStringList items = QStringList::split( '&', m_strQuery_encoded );
+  for ( QStringList::Iterator it = items.begin(); it != items.end(); ++it )
+  {
+    QString item = (*it);
+    if ( item.startsWith( _item ) ) 
+    {
+      int len = _item.length();
+      if ( item.length() > len && item.at( len ) == '=' )
+      {
+        if ( item.length() > len + 1 )
+          return item.mid( len + 1 );
+        else // empty value
+          return QString::fromLatin1("");
+      }
+    }
+  }
+
+  return QString::null;
+}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic