summaryrefslogtreecommitdiff
path: root/libutils/Unicode.cpp
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2016-05-16 13:21:09 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-05-16 13:21:11 +0000
commit8b452b876b90dcfff1dab9012b65b5e67c4531a4 (patch)
tree11453ade4ba6c05f8556d610fe824b2cc443570b /libutils/Unicode.cpp
parentc337cae9adcb538a4562641f97bdde933d085a82 (diff)
parent5bacef33c91e9625dfd09ecf638c2de7faecd34e (diff)
Merge "Add String16#contains and strstr16 methods." into nyc-dev
Diffstat (limited to 'libutils/Unicode.cpp')
-rw-r--r--libutils/Unicode.cpp29
1 files changed, 26 insertions, 3 deletions
diff --git a/libutils/Unicode.cpp b/libutils/Unicode.cpp
index 6f4b72176..ade896a02 100644
--- a/libutils/Unicode.cpp
+++ b/libutils/Unicode.cpp
@@ -222,11 +222,16 @@ int strncmp16(const char16_t *s1, const char16_t *s2, size_t n)
char16_t ch;
int d = 0;
- while ( n-- ) {
+ if (n == 0) {
+ return 0;
+ }
+
+ do {
d = (int)(ch = *s1++) - (int)*s2++;
- if ( d || !ch )
+ if ( d || !ch ) {
break;
- }
+ }
+ } while (--n);
return d;
}
@@ -284,6 +289,24 @@ size_t strnlen16(const char16_t *s, size_t maxlen)
return ss-s;
}
+char16_t* strstr16(const char16_t* src, const char16_t* target)
+{
+ const char16_t needle = *target++;
+ if (needle != '\0') {
+ do {
+ do {
+ if (*src == '\0') {
+ return nullptr;
+ }
+ } while (*src++ != needle);
+ } while (strcmp16(src, target) != 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;