[Libreoffice-commits] core.git: ucb/source

Noel Grandin noel.grandin at collabora.co.uk
Tue May 30 08:52:30 UTC 2017


 ucb/source/ucp/ftp/ftpurl.cxx |   81 +++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 40 deletions(-)

New commits:
commit deae9e88b960130f384f424ec8fce60a3d4e6297
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue May 30 10:03:40 2017 +0200

    FTPURL::parse doesn't need so much string conversion
    
    just do all the work on an OUString
    
    Change-Id: Id8c03203dd793fa9351d0d4d46a7726bafd7d814
    Reviewed-on: https://gerrit.libreoffice.org/38183
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/ucb/source/ucp/ftp/ftpurl.cxx b/ucb/source/ucp/ftp/ftpurl.cxx
index dd26810769c0..89a44774799e 100644
--- a/ucb/source/ucp/ftp/ftpurl.cxx
+++ b/ucb/source/ucp/ftp/ftpurl.cxx
@@ -32,6 +32,7 @@
 #include <com/sun/star/ucb/OpenMode.hpp>
 #include <string.h>
 #include <rtl/uri.hxx>
+#include <rtl/strbuf.hxx>
 
 #include "ftpurl.hxx"
 #include "ftpcontentprovider.hxx"
@@ -142,27 +143,25 @@ FTPURL::~FTPURL()
 
 void FTPURL::parse(const OUString& url)
 {
-    OUString aPassword,aAccount;
-    OString aIdent(url.getStr(),
-                        url.getLength(),
-                        RTL_TEXTENCODING_UTF8);
-
-    OString lower = aIdent.toAsciiLowerCase();
-    if(lower.getLength() < 6 ||
-       strncmp("ftp://",lower.getStr(),6))
-        throw malformed_exception();
-
-    std::unique_ptr<char[]> buffer(new char[1+aIdent.getLength()]);
-    const char* p2 = aIdent.getStr();
-    p2 += 6;
+    OUString aPassword, urlRest;
 
-    char ch;
-    char *p1 = buffer.get();      // determine "username:password at host:port"
-    while((ch = *p2++) != '/' && ch)
-        *p1++ = ch;
-    *p1 = 0;
+    if(url.getLength() < 6 || !url.startsWithIgnoreAsciiCase("ftp://"))
+        throw malformed_exception();
+    urlRest = url.copy(6);
 
-    OUString aExpr(buffer.get(), strlen(buffer.get()), RTL_TEXTENCODING_UTF8);
+    // determine "username:password at host:port"
+    OUString aExpr;
+    sal_Int32 nIdx = urlRest.indexOf('/');
+    if (nIdx == -1)
+    {
+        aExpr = urlRest;
+        urlRest = "";
+    }
+    else
+    {
+        aExpr = urlRest.copy(0, nIdx);
+        urlRest = urlRest.copy(nIdx + 1);
+    }
 
     sal_Int32 l = aExpr.indexOf('@');
     m_aHost = aExpr.copy(1+l);
@@ -177,7 +176,7 @@ void FTPURL::parse(const OUString& url)
                 m_bShowPassword = true;
         }
         if(l > 0)
-            // Overwritte only if the username is not empty.
+            // Overwritten only if the username is not empty.
             m_aUsername = aExpr.copy(0,l);
         else if(!aExpr.isEmpty())
             m_aUsername = aExpr;
@@ -195,34 +194,36 @@ void FTPURL::parse(const OUString& url)
         m_aHost = m_aHost.copy(0,l);
     }
 
-    while(ch) {  // now determine the pathsegments ...
-        p1 = buffer.get();
-        while((ch = *p2++) != '/' && ch)
-            *p1++ = ch;
-        *p1 = 0;
-
-        if(buffer[0]) {
-            if( strcmp(buffer.get(),"..") == 0 && !m_aPathSegmentVec.empty() && m_aPathSegmentVec.back() != ".." )
-                m_aPathSegmentVec.pop_back();
-            else if(strcmp(buffer.get(),".") == 0)
-                ; // Ignore
-            else
-                // This is a legal name.
-                m_aPathSegmentVec.push_back(
-                    OUString(buffer.get(),
-                                  strlen(buffer.get()),
-                                  RTL_TEXTENCODING_UTF8));
+    // now determine the pathsegments ...
+    while(!urlRest.isEmpty())
+    {
+        nIdx = urlRest.indexOf('/');
+        OUString segment;
+        if(nIdx == -1)
+        {
+            segment = urlRest;
+            urlRest = "";
+        }
+        else
+        {
+            segment = urlRest.copy(0, nIdx);
+            urlRest = urlRest.copy(nIdx + 1);
         }
+        if( segment == ".." && !m_aPathSegmentVec.empty() && m_aPathSegmentVec.back() != ".." )
+            m_aPathSegmentVec.pop_back();
+        else if( segment == "." )
+            ; // Ignore
+        else
+            // This is a legal name.
+            m_aPathSegmentVec.push_back( segment );
     }
 
-    buffer.reset();
-
     if(m_bShowPassword)
         m_pFCP->setHost(m_aHost,
                         m_aPort,
                         m_aUsername,
                         aPassword,
-                        aAccount);
+                        ""/*aAccount*/);
 
     // now check for something like ";type=i" at end of url
     if(m_aPathSegmentVec.size() &&


More information about the Libreoffice-commits mailing list