summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-04 20:08:22 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-04 20:08:22 +0000
commit2248697e7d6c5d9de6fc31a7261f36dffaa0a5d3 (patch)
tree34b153822fe1fbbd23817dafb38124907eb29c15 /webkit
parentd3dcc04318b8b55a5c3009251ea3686bdb46b4e8 (diff)
downloadchromium_src-2248697e7d6c5d9de6fc31a7261f36dffaa0a5d3.zip
chromium_src-2248697e7d6c5d9de6fc31a7261f36dffaa0a5d3.tar.gz
chromium_src-2248697e7d6c5d9de6fc31a7261f36dffaa0a5d3.tar.bz2
Add a method to the private API to search text using ICU.
Review URL: http://codereview.chromium.org/3607004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61409 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/glue/plugins/pepper_private.cc45
-rw-r--r--webkit/glue/plugins/ppb_private.h16
2 files changed, 61 insertions, 0 deletions
diff --git a/webkit/glue/plugins/pepper_private.cc b/webkit/glue/plugins/pepper_private.cc
index e35006b..58cd261 100644
--- a/webkit/glue/plugins/pepper_private.cc
+++ b/webkit/glue/plugins/pepper_private.cc
@@ -12,6 +12,7 @@
#include "grit/webkit_strings.h"
#include "skia/ext/platform_canvas.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/icu/public/i18n/unicode/usearch.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/plugins/pepper_image_data.h"
#include "webkit/glue/plugins/pepper_plugin_module.h"
@@ -162,11 +163,55 @@ bool GetFontTableForPrivateFontFile(PP_Resource font_file,
#endif
}
+void SearchString(PP_Module module,
+ const char16* string,
+ const char16* term,
+ bool case_sensitive,
+ PP_PrivateFindResult** results,
+ int* count) {
+ UErrorCode status = U_ZERO_ERROR;
+ UStringSearch* searcher = usearch_open(
+ term, -1, string, -1, webkit_glue::GetWebKitLocale().c_str(), 0,
+ &status);
+ UCollationStrength strength = case_sensitive ? UCOL_TERTIARY : UCOL_PRIMARY;
+
+ UCollator* collator = usearch_getCollator(searcher);
+ if (ucol_getStrength(collator) != strength) {
+ ucol_setStrength(collator, strength);
+ usearch_reset(searcher);
+ }
+
+ int match_start = usearch_first(searcher, &status);
+ DCHECK(status == U_ZERO_ERROR);
+
+ std::vector<PP_PrivateFindResult> pp_results;
+ while (match_start != USEARCH_DONE) {
+ size_t matched_length = usearch_getMatchedLength(searcher);
+ PP_PrivateFindResult result;
+ result.start_index = match_start;
+ result.length = matched_length;
+ pp_results.push_back(result);
+ match_start = usearch_next(searcher, &status);
+ }
+
+ *count = pp_results.size();
+ if (*count) {
+ *results = reinterpret_cast<PP_PrivateFindResult*>(
+ malloc(*count * sizeof(PP_PrivateFindResult)));
+ memcpy(*results, &pp_results[0], *count * sizeof(PP_PrivateFindResult));
+ } else {
+ *results = NULL;
+ }
+
+ usearch_close(searcher);
+}
+
const PPB_Private ppb_private = {
&GetLocalizedString,
&GetResourceImage,
&GetFontFileWithFallback,
&GetFontTableForPrivateFontFile,
+ &SearchString
};
} // namespace
diff --git a/webkit/glue/plugins/ppb_private.h b/webkit/glue/plugins/ppb_private.h
index 218f73a..9617b93 100644
--- a/webkit/glue/plugins/ppb_private.h
+++ b/webkit/glue/plugins/ppb_private.h
@@ -5,6 +5,7 @@
#ifndef WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_
#define WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_
+#include "base/string16.h"
#include "third_party/ppapi/c/pp_module.h"
#include "third_party/ppapi/c/pp_var.h"
@@ -82,6 +83,11 @@ struct PP_PrivateFontFileDescription {
PP_PrivateFontCharset charset;
};
+struct PP_PrivateFindResult {
+ int start_index;
+ int length;
+};
+
struct PPB_Private {
// Returns a localized string.
PP_Var (*GetLocalizedString)(PP_Module module, PP_ResourceString string_id);
@@ -102,6 +108,16 @@ struct PPB_Private {
uint32_t table,
void* output,
uint32_t* output_length);
+
+ // Search the given string using ICU. Use PPB_Core's MemFree on results when
+ // done.
+ void (*SearchString)(
+ PP_Module module,
+ const char16* string,
+ const char16* term,
+ bool case_sensitive,
+ PP_PrivateFindResult** results,
+ int* count);
};
#endif // WEBKIT_GLUE_PLUGINS_PPB_PRIVATE_H_