Disconnect relationship with VisualUrl and VisualFactory
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-url.cpp
index 97bc9b9..30d9c02 100644 (file)
@@ -34,15 +34,28 @@ VisualUrl::ProtocolType ResolveLocation(const std::string& url)
   const uint32_t length  = url.size();
   if((length > 7) && urlCStr[5] == ':' && urlCStr[6] == '/' && urlCStr[7] == '/')
   {
-    // https://
-    if(('h' == tolower(urlCStr[0])) &&
-       ('t' == tolower(urlCStr[1])) &&
-       ('t' == tolower(urlCStr[2])) &&
-       ('p' == tolower(urlCStr[3])) &&
-       ('s' == tolower(urlCStr[4])))
+    // https:// or enbuf://
+    const char hOre = tolower(urlCStr[0]);
+    const char tOrn = tolower(urlCStr[1]);
+    const char tOrb = tolower(urlCStr[2]);
+    const char pOru = tolower(urlCStr[3]);
+    const char sOrf = tolower(urlCStr[4]);
+    if(('h' == hOre) &&
+       ('t' == tOrn) &&
+       ('t' == tOrb) &&
+       ('p' == pOru) &&
+       ('s' == sOrf))
     {
       return VisualUrl::REMOTE;
     }
+    if(('e' == hOre) &&
+       ('n' == tOrn) &&
+       ('b' == tOrb) &&
+       ('u' == pOru) &&
+       ('f' == sOrf))
+    {
+      return VisualUrl::BUFFER;
+    }
   }
   else if((length > 6) && urlCStr[4] == ':' && urlCStr[5] == '/' && urlCStr[6] == '/')
   {
@@ -69,18 +82,20 @@ VisualUrl::ProtocolType ResolveLocation(const std::string& url)
   else if((length > 5) && urlCStr[3] == ':' && urlCStr[4] == '/' && urlCStr[5] == '/')
   {
     // ftp:// or ssh://
-    const char fOrS = tolower(urlCStr[0]);
-    if(('f' == fOrS) || ('s' == fOrS))
+    const char fOrs = tolower(urlCStr[0]);
+    const char tOrs = tolower(urlCStr[1]);
+    const char pOrh = tolower(urlCStr[2]);
+    if(('f' == fOrs) &&
+       ('t' == tOrs) &&
+       ('p' == pOrh))
     {
-      const char tOrs = tolower(urlCStr[1]);
-      if(('t' == tOrs) || ('s' == tOrs))
-      {
-        const char pOrh = tolower(urlCStr[2]);
-        if(('p' == pOrh) || ('h' == pOrh))
-        {
-          return VisualUrl::REMOTE;
-        }
-      }
+      return VisualUrl::REMOTE;
+    }
+    if(('s' == fOrs) &&
+       ('s' == tOrs) &&
+       ('h' == pOrh))
+    {
+      return VisualUrl::REMOTE;
     }
   }
   return VisualUrl::LOCAL;
@@ -103,12 +118,10 @@ VisualUrl::Type ResolveType(const std::string& url)
     char         GIF[4]    = {'f', 'i', 'g', '.'};
     char         WEBP[5]   = {'p', 'b', 'e', 'w', '.'};
     char         JSON[5]   = {'n', 'o', 's', 'j', '.'};
-    char         RIVE[4]   = {'v', 'i', 'r', '.'};
     unsigned int svgScore  = 0;
     unsigned int gifScore  = 0;
     unsigned int webpScore = 0;
     unsigned int jsonScore = 0;
-    unsigned int riveScore = 0;
     int          index     = count;
     while(--index >= 0)
     {
@@ -146,14 +159,6 @@ VisualUrl::Type ResolveType(const std::string& url)
           return VisualUrl::JSON;
         }
       }
-      if((offsetFromEnd < sizeof(RIVE)) && (currentChar == RIVE[offsetFromEnd]))
-      {
-        // early out if RIVE as can't be used in N patch for now
-        if(++riveScore == sizeof(RIVE))
-        {
-          return VisualUrl::RIVE;
-        }
-      }
       switch(state)
       {
         case SUFFIX:
@@ -214,9 +219,9 @@ VisualUrl::VisualUrl(const std::string& url)
   if(!url.empty())
   {
     mLocation = ResolveLocation(url);
-    if(VisualUrl::TEXTURE != mLocation)
+    if(VisualUrl::TEXTURE != mLocation && VisualUrl::BUFFER != mLocation)
     {
-      // TEXTURE location url doesn't need type resolving, REGULAR_IMAGE is fine
+      // TEXTURE and BUFFER location url doesn't need type resolving, REGULAR_IMAGE is fine
       mType = ResolveType(url);
     }
   }
@@ -229,6 +234,10 @@ VisualUrl::VisualUrl(const VisualUrl& url)
 {
 }
 
+VisualUrl::~VisualUrl()
+{
+}
+
 VisualUrl& VisualUrl::operator=(const VisualUrl& url)
 {
   if(&url != this)
@@ -265,14 +274,14 @@ bool VisualUrl::IsLocalResource() const
   return mLocation == VisualUrl::LOCAL;
 }
 
+bool VisualUrl::IsBufferResource() const
+{
+  return mLocation == VisualUrl::BUFFER;
+}
+
 std::string VisualUrl::GetLocation() const
 {
-  const auto location = mUrl.find("://");
-  if(std::string::npos != location)
-  {
-    return mUrl.substr(location + 3u); // 3 characters forwards from the start of ://
-  }
-  return mUrl;
+  return GetLocation(mUrl);
 }
 
 std::string VisualUrl::CreateTextureUrl(const std::string& location)
@@ -280,6 +289,26 @@ std::string VisualUrl::CreateTextureUrl(const std::string& location)
   return "dali://" + location;
 }
 
+std::string VisualUrl::CreateBufferUrl(const std::string& location)
+{
+  return "enbuf://" + location;
+}
+
+VisualUrl::ProtocolType VisualUrl::GetProtocolType(const std::string& url)
+{
+  return ResolveLocation(url);
+}
+
+std::string VisualUrl::GetLocation(const std::string& url)
+{
+  const auto location = url.find("://");
+  if(std::string::npos != location)
+  {
+    return url.substr(location + 3u); // 3 characters forwards from the start of ://
+  }
+  return url;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit