summaryrefslogtreecommitdiff
path: root/libutils/Unicode.cpp
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-10-24 20:20:00 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-10-24 20:20:00 +0000
commitb128c78aef290f0eb0a5fc989a53a39c89a131c9 (patch)
tree4f7c2e3c1e528c89c9e3eaaa80a5657b91850816 /libutils/Unicode.cpp
parent0f2097c0f03760080322705c5ef8fcc836cc6419 (diff)
parentbf3fff1a9ed39d005f36db43c9893697e0a006a3 (diff)
Merge "libutils: Fix bug in strstr16."
Diffstat (limited to 'libutils/Unicode.cpp')
-rw-r--r--libutils/Unicode.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index 5fd915524..e7520a8e8 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -297,23 +297,22 @@ size_t strnlen16(const char16_t *s, size_t maxlen)
char16_t* strstr16(const char16_t* src, const char16_t* target)
{
- const char16_t needle = *target++;
- const size_t target_len = strlen16(target);
- if (needle != '\0') {
- do {
+ const char16_t needle = *target;
+ if (needle == '\0') return (char16_t*)src;
+
+ const size_t target_len = strlen16(++target);
+ do {
do {
- if (*src == '\0') {
- return nullptr;
- }
+ if (*src == '\0') {
+ return nullptr;
+ }
} while (*src++ != needle);
- } while (strncmp16(src, target, target_len) != 0);
- src--;
- }
+ } while (strncmp16(src, target, target_len) != 0);
+ src--;
return (char16_t*)src;
}
-
int strzcmp16(const char16_t *s1, size_t n1, const char16_t *s2, size_t n2)
{
const char16_t* e1 = s1+n1;