Commit 3f80a26c authored by Tommy Martino's avatar Tommy Martino Committed by Commit Bot

[SH iOS] Cleanup for "Adding text fragment parsing"

This CL addresses a few comments that were received after landing
https://chromium-review.googlesource.com/c/chromium/src/+/2337407

Bug: 1099268
Change-Id: Ieb8fa406f69fc28ab15ce89d79030d93b39cc8ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2341665
Commit-Queue: Tommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796172}
parent 40ac21ec
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#import "ios/web/navigation/text_fragment_utils.h" #import "ios/web/navigation/text_fragment_utils.h"
#include <cstring.h>
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "ios/web/common/features.h" #include "ios/web/common/features.h"
#import "ios/web/public/navigation/navigation_context.h" #import "ios/web/public/navigation/navigation_context.h"
...@@ -14,8 +16,10 @@ ...@@ -14,8 +16,10 @@
#endif #endif
namespace { namespace {
const std::string kDirectivePrefix = ":~:";
const std::string kTextFragmentPrefix = "text="; const char kDirectivePrefix[] = ":~:";
const char kTextFragmentPrefix[] = "text=";
} // namespace } // namespace
namespace web { namespace web {
...@@ -63,7 +67,7 @@ std::vector<std::string> ExtractTextFragments(std::string ref_string) { ...@@ -63,7 +67,7 @@ std::vector<std::string> ExtractTextFragments(std::string ref_string) {
size_t start_pos = ref_string.find(kDirectivePrefix); size_t start_pos = ref_string.find(kDirectivePrefix);
if (start_pos == std::string::npos) if (start_pos == std::string::npos)
return {}; return {};
ref_string.erase(0, start_pos + kDirectivePrefix.size()); ref_string.erase(0, start_pos + strlen(kDirectivePrefix));
std::vector<std::string> fragment_strings; std::vector<std::string> fragment_strings;
while (ref_string.size()) { while (ref_string.size()) {
...@@ -71,7 +75,7 @@ std::vector<std::string> ExtractTextFragments(std::string ref_string) { ...@@ -71,7 +75,7 @@ std::vector<std::string> ExtractTextFragments(std::string ref_string) {
size_t prefix_pos = ref_string.find(kTextFragmentPrefix); size_t prefix_pos = ref_string.find(kTextFragmentPrefix);
if (prefix_pos == std::string::npos) if (prefix_pos == std::string::npos)
break; break;
ref_string.erase(0, prefix_pos + kTextFragmentPrefix.size()); ref_string.erase(0, prefix_pos + strlen(kTextFragmentPrefix));
// A & indicates the end of the fragment (and the start of the next). // A & indicates the end of the fragment (and the start of the next).
// Save everything up to this point, and then consume it (including the &). // Save everything up to this point, and then consume it (including the &).
......
...@@ -18,12 +18,16 @@ ...@@ -18,12 +18,16 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
namespace {
// These values correspond to the members that the JavaScript implementation is // These values correspond to the members that the JavaScript implementation is
// expecting. // expecting.
const std::string kPrefixKey = "prefix"; const char kPrefixKey[] = "prefix";
const std::string kTextStartKey = "textStart"; const char kTextStartKey[] = "textStart";
const std::string kTextEndKey = "textEnd"; const char kTextEndKey[] = "textEnd";
const std::string kSuffixKey = "suffix"; const char kSuffixKey[] = "suffix";
} // namespace
namespace web { namespace web {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment