Move text_encoding_map_efl outside of ewk public directory
authorArnaud Renevier <a.renevier@samsung.com>
Tue, 5 May 2015 23:30:58 +0000 (16:30 -0700)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
In addition, we make TextEncodingMapEfl a singleton class.

And also, we optimize the search by using a hash set instead of a list.
Search time in now constant time.

Change-Id: I22d8830b2d04c6bd4d4d4ba56fadb42950479d59
Signed-off-by: Arnaud Renevier <a.renevier@samsung.com>
tizen_src/ewk/efl_integration/efl_integration.gypi
tizen_src/ewk/efl_integration/public/ewk_settings.cc
tizen_src/ewk/efl_integration/public/text_encoding_map_efl.h [deleted file]
tizen_src/ewk/efl_integration/text_encoding_map_efl.cc [moved from tizen_src/ewk/efl_integration/public/text_encoding_map_efl.cc with 69% similarity]
tizen_src/ewk/efl_integration/text_encoding_map_efl.h [new file with mode: 0644]

index 5a7d139..2059370 100644 (file)
       'popup_controller_efl.h',
       'scroll_detector.cc',
       'scroll_detector.h',
+      'text_encoding_map_efl.cc',
+      'text_encoding_map_efl.h',
       'selection_box_efl.cc',
       'selection_box_efl.h',
       'selection_controller_efl.cc',
       'public/ewk_export.h',
       'public/ewk_log.h',
       'public/ewk_touch.h',
-      'public/text_encoding_map_efl.cc',
-      'public/text_encoding_map_efl.h',
 
       'browser/web_view_evas_handler.cc',
       'browser/web_view_evas_handler.h',
index 5432c27..d3ca776 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "eweb_view.h"
 #include "ui/events/gesture_detection/gesture_configuration.h"
-#include "public/text_encoding_map_efl.h"
+#include "text_encoding_map_efl.h"
 #include "private/ewk_private.h"
 #include "private/ewk_private.h"
 #include "private/ewk_settings_private.h"
@@ -191,7 +191,7 @@ Eina_Bool ewk_settings_default_encoding_set(Ewk_Settings* settings, const char*
 
 Eina_Bool ewk_settings_is_encoding_valid(const char* encoding)
 {
-  return TextEncodingMapEfl::isTextEncodingValid(encoding);
+  return TextEncodingMapEfl::GetInstance()->isTextEncodingValid(encoding);
 }
 
 const char* ewk_settings_default_encoding_get(const Ewk_Settings* settings)
diff --git a/tizen_src/ewk/efl_integration/public/text_encoding_map_efl.h b/tizen_src/ewk/efl_integration/public/text_encoding_map_efl.h
deleted file mode 100644 (file)
index 6488e4c..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2013 Samsung Electronics. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// TODO: move this file to somewhere not ewk public directory
-#ifndef TextEncodingMapEfl_h
-#define TextEncodingMapEfl_h
-
-class TextEncodingMapEfl {
- public:
-  static bool isTextEncodingValid(const char* name);
-};
-
-#endif // TextEncodingRegistry_h
@@ -2,16 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// TODO: move this file to other location than ewk's public
-
-#include "public/text_encoding_map_efl.h"
-
-// TODO: remove strings.h because it's non-standard.
-#include <strings.h>
+#include "text_encoding_map_efl.h"
 
 #include <string>
 
-namespace{
+namespace {
 
   // The below Encodings have been taken from
   // chromium/src/third_party/WebKit/Source/wtf/text/TextCodecLatin1.cpp
@@ -26,7 +21,7 @@ namespace{
   // The character encoding list used by chrome browser is also used as reference. It is located in :
   // chromium/src/chrome/browser/character_encoding.cc
 
-const std::string TextEncodingNameMap[] = {
+const std::vector<std::string> TextEncodingNameMap = {
 "windows-1252",
 "ISO-8859-1",
 "US-ASCII",
@@ -77,18 +72,24 @@ const std::string TextEncodingNameMap[] = {
 
 } //namespace
 
-const size_t maxEncodingNameLength = 63;
-const size_t textEncodingNameMapLength = 46;
-
 //static
-bool TextEncodingMapEfl::isTextEncodingValid(const char* name)
-{
- if (!name || !name[0] || (std::string(name).length() > maxEncodingNameLength))
-  return 0;
+TextEncodingMapEfl* TextEncodingMapEfl::GetInstance() {
+  return Singleton<TextEncodingMapEfl>::get();
+}
+
+bool TextEncodingMapEfl::isTextEncodingValid(const char* name) {
+  if (!name || !name[0])
+    return 0;
+
+  std::string str(name);
+  std::transform(str.begin(), str.end(), str.begin(), ::tolower);
+  return encoding_name_set_.find(str) != encoding_name_set_.end();
+}
 
- for (size_t i = 0; i < textEncodingNameMapLength; i++) {
-   if (!strcasecmp(TextEncodingNameMap[i].c_str(), name))
-    return true;
- }
- return false;
+TextEncodingMapEfl::TextEncodingMapEfl() {
+  for (size_t i = 0; i < TextEncodingNameMap.size(); i++) {
+    std::string name = TextEncodingNameMap[i];
+    std::transform(name.begin(), name.end(), name.begin(), ::tolower);
+    encoding_name_set_.insert(name);
+  }
 }
diff --git a/tizen_src/ewk/efl_integration/text_encoding_map_efl.h b/tizen_src/ewk/efl_integration/text_encoding_map_efl.h
new file mode 100644 (file)
index 0000000..14dc309
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2013 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TextEncodingMapEfl_h
+#define TextEncodingMapEfl_h
+
+#include "base/memory/singleton.h"
+
+#include <Eina.h>
+#include "base/containers/hash_tables.h"
+
+template <typename T> struct DefaultSingletonTraits;
+
+class TextEncodingMapEfl {
+ public:
+  static TextEncodingMapEfl* GetInstance();
+  bool isTextEncodingValid(const char* name);
+ private:
+  friend struct DefaultSingletonTraits<TextEncodingMapEfl>;
+  TextEncodingMapEfl();
+  base::hash_set<std::string> encoding_name_set_;
+};
+
+#endif // TextEncodingRegistry_h