svgio/inc/svgtools.hxx                     |    1 +
 svgio/source/svgreader/svggradientnode.cxx |    9 ++-------
 svgio/source/svgreader/svgpatternnode.cxx  |    9 ++-------
 svgio/source/svgreader/svgtextpathnode.cxx |    7 +------
 svgio/source/svgreader/svgtools.cxx        |   25 +++++++++++++++++++------
 svgio/source/svgreader/svgtrefnode.cxx     |    7 +------
 svgio/source/svgreader/svgusenode.cxx      |    7 +------
 7 files changed, 27 insertions(+), 38 deletions(-)

New commits:
commit a5d3238104a46f933584cc2a896b00bae82bf4ec
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jul 14 12:39:42 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jul 14 14:34:21 2022 +0200

    svgio: factor out common code
    
    Also skip spaces before the #, Something like
    xlink:href="     #target" is still valid
    
    Change-Id: Ia62e58ca31bfecd283776ec84fcc4bba1836afab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137074
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/svgio/inc/svgtools.hxx b/svgio/inc/svgtools.hxx
index f5e2e03573e6..a5a0b3aa418b 100644
--- a/svgio/inc/svgtools.hxx
+++ b/svgio/inc/svgtools.hxx
@@ -111,6 +111,7 @@ namespace svgio::svgreader
         basegfx::B2DRange readViewBox(const OUString& rCandidate, InfoProvider 
const & rInfoProvider);
         basegfx::B2DHomMatrix readTransform(const OUString& rCandidate, 
InfoProvider const & rInfoProvider);
         bool readSingleNumber(const OUString& rCandidate, SvgNumber& aNum);
+        bool readLocalLink(const OUString& rCandidate, OUString& rURL);
         bool readLocalUrl(const OUString& rCandidate, OUString& rURL);
         bool readSvgPaint(const OUString& rCandidate, SvgPaint& rSvgPaint, 
OUString& rURL, SvgNumber& rOpacity);
 
diff --git a/svgio/source/svgreader/svggradientnode.cxx 
b/svgio/source/svgreader/svggradientnode.cxx
index a6f99f7e5009..7355a1ee22fd 100644
--- a/svgio/source/svgreader/svggradientnode.cxx
+++ b/svgio/source/svgreader/svggradientnode.cxx
@@ -215,13 +215,8 @@ namespace svgio::svgreader
                 case SVGToken::Href:
                 case SVGToken::XlinkHref:
                 {
-                    const sal_Int32 nLen(aContent.getLength());
-
-                    if(nLen && '#' == aContent[0])
-                    {
-                        maXLink = aContent.copy(1);
-                        tryToFindLink();
-                    }
+                    readLocalLink(aContent, maXLink);
+                    tryToFindLink();
                     break;
                 }
                 default:
diff --git a/svgio/source/svgreader/svgpatternnode.cxx 
b/svgio/source/svgreader/svgpatternnode.cxx
index c8dad353713f..b2f4785b4631 100644
--- a/svgio/source/svgreader/svgpatternnode.cxx
+++ b/svgio/source/svgreader/svgpatternnode.cxx
@@ -170,13 +170,8 @@ namespace svgio::svgreader
                 case SVGToken::Href:
                 case SVGToken::XlinkHref:
                 {
-                    const sal_Int32 nLen(aContent.getLength());
-
-                    if(nLen && '#' == aContent[0])
-                    {
-                        maXLink = aContent.copy(1);
-                        tryToFindLink();
-                    }
+                    readLocalLink(aContent, maXLink);
+                    tryToFindLink();
                     break;
                 }
                 default:
diff --git a/svgio/source/svgreader/svgtextpathnode.cxx 
b/svgio/source/svgreader/svgtextpathnode.cxx
index 43fccfa4308f..3c5471bbd946 100644
--- a/svgio/source/svgreader/svgtextpathnode.cxx
+++ b/svgio/source/svgreader/svgtextpathnode.cxx
@@ -295,12 +295,7 @@ namespace svgio::svgreader
                 case SVGToken::Href:
                 case SVGToken::XlinkHref:
                 {
-                    const sal_Int32 nLen(aContent.getLength());
-
-                    if(nLen && '#' == aContent[0])
-                    {
-                        maXLink = aContent.copy(1);
-                    }
+                    readLocalLink(aContent, maXLink);
                     break;
                 }
                 default:
diff --git a/svgio/source/svgreader/svgtools.cxx 
b/svgio/source/svgreader/svgtools.cxx
index c559bd620fbf..7ab816f9a84d 100644
--- a/svgio/source/svgreader/svgtools.cxx
+++ b/svgio/source/svgreader/svgtools.cxx
@@ -1057,6 +1057,24 @@ namespace svgio::svgreader
             return readNumberAndUnit(rCandidate, nPos, aNum, nLen);
         }
 
+        bool readLocalLink(const OUString& rCandidate, OUString& rURL)
+        {
+            sal_Int32 nPos(0);
+            const sal_Int32 nLen(rCandidate.getLength());
+
+            skip_char(rCandidate, ' ', nPos, nLen);
+
+            if(nLen && '#' == rCandidate[nPos])
+            {
+                ++nPos;
+                rURL = rCandidate.copy(nPos);
+
+                return true;
+            }
+
+            return false;
+        }
+
         bool readLocalUrl(const OUString& rCandidate, OUString& rURL)
         {
             static const char aStrUrl[] = "url(";
@@ -1308,12 +1326,7 @@ namespace svgio::svgreader
             rMimeType.clear();
             rData.clear();
 
-            if('#' == rCandidate[0])
-            {
-                // local link
-                rXLink = rCandidate.copy(1);
-            }
-            else
+            if(!readLocalLink(rCandidate, rXLink))
             {
                 static const char aStrData[] = "data:";
 
diff --git a/svgio/source/svgreader/svgtrefnode.cxx 
b/svgio/source/svgreader/svgtrefnode.cxx
index 274ceb3972ce..1e807f5199f4 100644
--- a/svgio/source/svgreader/svgtrefnode.cxx
+++ b/svgio/source/svgreader/svgtrefnode.cxx
@@ -58,12 +58,7 @@ namespace svgio::svgreader
                 case SVGToken::Href:
                 case SVGToken::XlinkHref:
                 {
-                    const sal_Int32 nLen(aContent.getLength());
-
-                    if(nLen && '#' == aContent[0])
-                    {
-                        maXLink = aContent.copy(1);
-                    }
+                    readLocalLink(aContent, maXLink);
                     break;
                 }
                 default:
diff --git a/svgio/source/svgreader/svgusenode.cxx 
b/svgio/source/svgreader/svgusenode.cxx
index d3d4331b7abb..903770b9522c 100644
--- a/svgio/source/svgreader/svgusenode.cxx
+++ b/svgio/source/svgreader/svgusenode.cxx
@@ -116,12 +116,7 @@ namespace svgio::svgreader
                 case SVGToken::Href:
                 case SVGToken::XlinkHref:
                 {
-                    const sal_Int32 nLen(aContent.getLength());
-
-                    if(nLen && '#' == aContent[0])
-                    {
-                        maXLink = aContent.copy(1);
-                    }
+                    readLocalLink(aContent, maXLink);
                     break;
                 }
                 default:

Reply via email to