remove sneaked inserting unicodes, zero-width no-break space.
[platform/core/uifw/lottie-player.git] / src / lottie / lottieloader.cpp
index a948e4a..d3474a9 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 #include "lottieloader.h"
 #include "lottieparser.h"
 
@@ -14,8 +30,8 @@ public:
 
         return CACHE;
     }
-    std::shared_ptr<LOTModel> find(std::string &key);
-    void add(std::string &key, std::shared_ptr<LOTModel> value);
+    std::shared_ptr<LOTModel> find(const std::string &key);
+    void add(const std::string &key, std::shared_ptr<LOTModel> value);
 
 private:
     LottieFileCache() = default;
@@ -23,7 +39,7 @@ private:
     std::unordered_map<std::string, std::shared_ptr<LOTModel>> mHash;
 };
 
-std::shared_ptr<LOTModel> LottieFileCache::find(std::string &key)
+std::shared_ptr<LOTModel> LottieFileCache::find(const std::string &key)
 {
     auto search = mHash.find(key);
     if (search != mHash.end()) {
@@ -33,12 +49,12 @@ std::shared_ptr<LOTModel> LottieFileCache::find(std::string &key)
     }
 }
 
-void LottieFileCache::add(std::string &key, std::shared_ptr<LOTModel> value)
+void LottieFileCache::add(const std::string &key, std::shared_ptr<LOTModel> value)
 {
-    mHash[key] = value;
+    mHash[key] = std::move(value);
 }
 
-bool LottieLoader::load(std::string &path)
+bool LottieLoader::load(const std::string &path)
 {
     LottieFileCache &fileCache = LottieFileCache::get();
 
@@ -65,6 +81,20 @@ bool LottieLoader::load(std::string &path)
     return true;
 }
 
+bool LottieLoader::loadFromData(std::string &&jsonData, const std::string &key)
+{
+    LottieFileCache &fileCache = LottieFileCache::get();
+
+    mModel = fileCache.find(key);
+    if (mModel) return true;
+
+    LottieParser parser(const_cast<char *>(jsonData.c_str()));
+    mModel = parser.model();
+    fileCache.add(key, mModel);
+
+    return true;
+}
+
 std::shared_ptr<LOTModel> LottieLoader::model()
 {
     return mModel;